[<<][c][>>][..]
Sun Mar 9 12:21:29 CET 2014

C++ allocators

I'd like to wrap a chunk of memory as a shared_ptr<vector<uint8_t> >,
and then manually assert that the refcount is 1 after pushing it
through some network.

template <typename T>
class slice: public std::allocator<T> {
public:
  T* allocate(size_t n, const void *hint=0) {
    LOG("allocate(%d,%p)\n", n, hint);
    return (T*)_data;
  }
  void deallocate(T* p, size_t n) {
    LOG("deallocate(%p,n)\n", p, n);
  }
  slice(U8 *data, U32 data_length) :
    _data(data),
    _data_length(data_length) { }
private:
  U8 *_data;
  U32 _data_length;
};



[Reply][About]
[<<][c][>>][..]