8 #include "MemoryIArchive.h" 9 #include "MemoryOArchive.h" 10 #include <util/misc/Memory.h> 37 if (buffer_ && ownsData_) {
39 Memory::deallocate<Byte>(buffer_, capacity_ +
sizeof(size_t));
52 Memory::allocate<Byte>(buffer_, capacity +
sizeof(size_t));
53 begin_ = buffer_ +
sizeof(size_t);
67 UTIL_THROW(
"This MemoryIArchive is already allocated");
69 buffer_ = other.buffer_;
70 begin_ = other.begin_;
71 cursor_ = other.begin_;
73 endAllocated_ = other.endAllocated_;
74 capacity_ = other.capacity_;
76 oArchivePtr_ = &other;
77 other.isLocked_ =
true;
113 UTIL_THROW(
"This archive has no associated data");
125 oArchivePtr_->isLocked_ =
false;
135 int myRank = comm.Get_rank();
136 int comm_size = comm.Get_size();
139 if (source > comm_size - 1 || source < 0) {
142 if (source == myRank) {
143 UTIL_THROW(
"Source and desination identical");
146 size_t recvCapacity = capacity_ +
sizeof(size_t);
147 comm.Recv(buffer_, recvCapacity, MPI::UNSIGNED_CHAR, source, 5);
149 begin_ = buffer_ +
sizeof(size_t);
152 size_t* sizePtr = (
size_t*) buffer_;
153 size_t size = *sizePtr;
154 end_ = buffer_ + size;
163 const unsigned int version)
165 static std::vector<char> charvec;
168 if (size > charvec.capacity()) {
169 charvec.reserve(size + 8);
171 ar.
unpack(&charvec[0], size);
size_t capacity() const
Return capacity in Bytes.
MemoryIArchive & operator=(MemoryOArchive &other)
Assignment from MemoryOArchive.
void reset()
Reset the cursor to the beginning (for rereading).
void release()
Release memory obtained by assignment.
MemoryIArchive()
Constructor.
void allocate(size_t capacity)
Allocate memory block.
void unpack(T &data)
Unpack one object of type T.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Save archive for packed heterogeneous binary data.
Utility classes for scientific computation.
void clear()
Reset to empty state.
Byte * begin() const
Return pointer to beginning of block.
bool isAllocated() const
Has memory been allocated?
void recv(MPI::Intracomm &comm, int source)
Receive packed data via MPI.
~MemoryIArchive()
Destructor.
Input archive for packed heterogeneous binary data.