Alex Rivera | Logout

Does STL Vector use 'new' and 'delete' for memory allocation by default?

Asked 2010-11-11T21:53:10.407
10

I am working on a plugin for an application, where the memory should be allocated by the Application and keep track of it. Hence, memory handles should be obtained from the host application in the form of buffers and later on give them back to the application. Now, I am planning on using STL Vectors and I am wondering what sort of memory allocation does it use internally.

Does it use 'new' and 'delete' functions internally? If so, can I just overload 'new' and 'delete' with my own functions? Or should I create my own template allocator which looks like a difficult job for me since I am not that experienced in creating custom templates.

Any suggestions/sample code are welcome. Memory handles can be obtained from the application like this

void* bufferH = NULL;

bufferH = MemReg()->New_Mem_Handle(size_of_buffer);
MemReg()->Dispose_Mem_Handle(bufferH); //Dispose it
Edit
Report

1 Answer

2

From this article, "The concept of allocators was originally introduced to provide an abstraction for different memory models to handle the problem of having different pointer types on certain 16-bit operating systems (such as near, far, and so forth)" ...

"The standard provides an allocator that internally uses the global operators 'new' and 'delete'"

The author also points out the alocator interface isn't that scary. As Neil Buchanan would say, "try it yourself!"

answered 2010-11-11T22:01:54.103

Your Answer