Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>create a class and overload new only in this class. you will not have problems with your vector. you will be able to use your own new with <code>::new A</code> and the normal new with <code>new A</code></p> <pre><code>class C { public: void* operator new( size_t n ) ; // ... } ; </code></pre> <p>otherwise, you can use your own <s>operator</s> function rather than overload operator new : </p> <p>a basic idea of an allocator :</p> <pre><code>int *i = myGetMem(i); // and myGetMem() allocates sizeof(*i) bytes of memory. </code></pre> <p>so you will not have problems with using the vector.</p> <hr> <p>in fact, a real memory allocator keeps the information you put on the vector in the memory allocated it self : </p> <p>you can take an algorithm for getmem/freemem to adapt it to your case. it can be helpfull.</p> <p>e.g. : i want to allocate 10 bytes, the memory at @1024 contain information about memory allocated and the allocator returns an adress after 1024, maybe @1030 (depending of the information stored) as the start of allocated memory. so the user gets adress 1030 and he has memory between 1030 and 103A.</p> <p>when calling the deallocator, the information at the beginning is used to correctly free the memory and to put it back in the list of avaible memory.</p> <p>(the list of availvle memory is stored in popular alorithms in an array of linked lists of free memories organized by size with algorithms to avoid and minimize fragmentation)</p> <p>this can resolve your need to the vector.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload