X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=schemaparser%2Fblock_allocator.h;fp=schemaparser%2Fblock_allocator.h;h=caa6aa4598aa727e0732b51c8ed5b74b2dc70e30;hb=783f6bfa93c3eed4787bded3c35016952b74b2e3;hp=0000000000000000000000000000000000000000;hpb=5b238b84dd6a6fb77a68f9b37906b465ab08a7fd;p=ric-app%2Fmc.git diff --git a/schemaparser/block_allocator.h b/schemaparser/block_allocator.h new file mode 100644 index 0000000..caa6aa4 --- /dev/null +++ b/schemaparser/block_allocator.h @@ -0,0 +1,40 @@ +// Distributed under the MIT license. Copyright (c) 2010, Ivan Vashchaev + + +#ifndef BLOCK_ALLOCATOR_H +#define BLOCK_ALLOCATOR_H + +namespace mc_json{ +class block_allocator +{ +private: + struct block + { + size_t size; + size_t used; + char *buffer; + block *next; + }; + + block *m_head; + size_t m_blocksize; + + block_allocator(const block_allocator &); + block_allocator &operator=(block_allocator &); + +public: + block_allocator(size_t blocksize); + ~block_allocator(); + + // exchange contents with rhs + void swap(block_allocator &rhs); + + // allocate memory + void *malloc(size_t size); + + // free all allocated blocks + void free(); +}; +} + +#endif