Thrill  0.1
memory_file.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/memory_file.hpp
3  *
4  * Part of FOXXLL. See http://foxxll.org
5  *
6  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
7  * Copyright (C) 2009 Johannes Singler <[email protected]>
8  * Copyright (C) 2014 Timo Bingmann <[email protected]>
9  *
10  * Distributed under the Boost Software License, Version 1.0.
11  * (See accompanying file LICENSE_1_0.txt or copy at
12  * http://www.boost.org/LICENSE_1_0.txt)
13  **************************************************************************/
14 
15 #ifndef FOXXLL_IO_MEMORY_FILE_HEADER
16 #define FOXXLL_IO_MEMORY_FILE_HEADER
17 
18 #include <mutex>
19 
21 #include <foxxll/io/request.hpp>
22 
23 namespace foxxll {
24 
25 //! \addtogroup foxxll_fileimpl
26 //! \{
27 
28 //! Implementation of file based on new[] and memcpy.
29 class memory_file final : public disk_queued_file
30 {
31  //! pointer to memory area of "file"
32  char* ptr_;
33 
34  //! size of memory area
36 
37  //! sequentialize function calls
38  std::mutex mutex_;
39 
40 public:
41  //! constructs file object.
43  int queue_id = DEFAULT_QUEUE,
44  int allocator_id = NO_ALLOCATOR,
45  unsigned int device_id = DEFAULT_DEVICE_ID)
46  : file(device_id),
47  disk_queued_file(queue_id, allocator_id),
48  ptr_(nullptr), size_(0)
49  { }
50  void serve(void* buffer, offset_type offset, size_type bytes,
51  request::read_or_write op) final;
52  ~memory_file();
53  offset_type size() final;
54  void set_size(offset_type newsize) final;
55  void lock() final;
56  void discard(offset_type offset, offset_type size) final;
57  const char * io_type() const final;
58 };
59 
60 //! \}
61 
62 } // namespace foxxll
63 
64 #endif // !FOXXLL_IO_MEMORY_FILE_HEADER
65 
66 /**************************************************************************/
void set_size(offset_type newsize) final
Definition: memory_file.cpp:64
const char * io_type() const final
Definition: memory_file.cpp:43
void serve(void *buffer, offset_type offset, size_type bytes, request::read_or_write op) final
Definition: memory_file.cpp:26
static const unsigned int DEFAULT_DEVICE_ID
Definition: file.hpp:92
request::offset_type offset_type
the offset of a request, also the size of the file
Definition: file.hpp:58
Implementation of some file methods based on serving_request.
offset_type size() final
Definition: memory_file.cpp:59
memory_file(int queue_id=DEFAULT_QUEUE, int allocator_id=NO_ALLOCATOR, unsigned int device_id=DEFAULT_DEVICE_ID)
constructs file object.
Definition: memory_file.hpp:42
request::size_type size_type
the size of a request
Definition: file.hpp:60
offset_type size_
size of memory area
Definition: memory_file.hpp:35
static const int DEFAULT_QUEUE
Definition: file.hpp:89
FOXXLL library namespace
static const size_t bytes
number of bytes in uint_pair
Definition: uint_types.hpp:75
static const int NO_ALLOCATOR
Definition: file.hpp:91
void lock() final
Locks file for reading and writing (acquires a lock in the file system).
Definition: memory_file.cpp:54
std::mutex mutex_
sequentialize function calls
Definition: memory_file.hpp:38
void discard(offset_type offset, offset_type size) final
Definition: memory_file.cpp:73
Implementation of file based on new[] and memcpy.
Definition: memory_file.hpp:29
char * ptr_
pointer to memory area of "file"
Definition: memory_file.hpp:32