hmbdc
simplify-high-performance-messaging-programming
DownloadMemory.hpp
1 #include "hmbdc/Copyright.hpp"
2 #pragma once
3 
4 #include <fstream>
5 #include <stdint.h>
6 #include <stdlib.h>
7 
8 
9 namespace hmbdc { namespace os {
12  : addr_(nullptr)
13  , fullLen_(0)
14  , len_(0) {
15  }
16 
17  void* open(size_t len) {
18  addr_ = (char*)memalign(SMP_CACHE_BYTES, len);
19  if (addr_) {
20  fullLen_ = len;
21  len_ = 0;
22  return addr_;
23  }
24  return nullptr;
25  }
26 
27  explicit operator bool() const {
28  return addr_;
29  }
30 
31  bool writeDone() const {
32  return fullLen_ == len_;
33  }
34 
35  size_t write(void const* mem, size_t l) {
36  auto wl = std::min(l, fullLen_ - len_);
37  if (addr_) {
38  memcpy(addr_ + len_, mem, wl);
39  }
40  len_ += wl;
41  return wl;
42  }
43 
44  size_t fullLen() const {
45  return fullLen_;
46  }
47 
48  void close() {
49  addr_ = nullptr;
50  fullLen_ = 0;
51  len_ = 0;
52  }
53 
54 private:
55  char* addr_;
56  size_t fullLen_;
57  size_t len_;
58 
59 };
60 
61 }}
Definition: DownloadMemory.hpp:10
Definition: Base.hpp:12