Circular LinkList using a custom shared Allocator
I have been given the following skeleton to implement. Below you can find an unimplemented API of the circular list and simple memory allocator. The goal of the task is to finish the implementation to have ready to use container that uses custom allocator.
Here are the constraints -
No dynamic allocation (new, malloc, etc.) There is one allocator for multiple CircularList objects Solution has to be thread safe. Make it as cache friendly as possible Make it as optimal as you can You can add new members to classes/structs if needed but you shouldn't Change prototypes of existing member functions template class ListAllocator { public: DataType* allocate(size_t size) { // TODO: implement } void deallocate() { // TODO: implement } private: static constexpr unsigned int MAX_DATA_SIZE = 2048; unsigned char storage[MAX_DATA_SIZE]; }; template > class CircularList { // TODO: implement CircularList public: // Adds new element to the end of the list void push_back(DataType value) { // TODO: implement } // Adds new element to the beginning of the list void push_front(DataType value) { // TODO: implement } // Inserts new element after provided node void insert_after(Node* node, DataType value) { // TODO: implement } // Removes last element from the list and returns it DataType pop_back() { // TODO: implement } // Removes first element from the list end returns it DataType pop_front() { // TODO: implement } private: static Allocator allocator; }; I have few questions : 1. Do I have maximum 2k memory for the use ? 2. When I can't use malloc/new and free/delete , should I have use placement new or Is there any other way ? 3. What kind of unimplemented API that I need to write ? 4. What needs to be done for making one allocator for multiple circular list objects ? I have seen general template allocator written which uses malloc/new and free/delete, but I am unable to understand this skeleton. As I confused what to use , if I am unable to use malloc/new and free/delete. Can you please help by writing some code ?
Aucun commentaire:
Enregistrer un commentaire