473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Building Allocators

Heya everyone!
A Q for U...
I need to build an allocator for my objects, but! the trick is that:

* Allocator would manage his own MemAlloc And the MemFree (like dhu)
* One class could use a few types of allocators (meaning allocator is
not a static member of the class).
* I want the minimal overhead on a programmer, meaning that once he
attached an allocator to an object he wont need to remember what
allocator he attached (fire and forget)

* I could overload new and delete and use the allocator within them

One solution was makin the allocator a member of an object BUT new and
delete are defined as static functions and could only use a static
members. once i'll attach an allocator to an object all objects of the
type will use the same allocator... BAD (think what will happen if i
allocate an object with one allocator and free it with another)

Another solution was adding the allocator to the new and delete
operators, two major problems
1) i could live with specifing the allocator as an argument in the new
operator but, in the delete? two much overhead
2) the overloaded deltet doesnt work! i call it delete(new Allocator())
Object; and it redirects to the normal delete!

I think u got my drift ... its more of a design problem
I'll be happy to hear your thoughts

Jan 2 '07 #1
1 1345
ManicQin wrote:
Heya everyone!
A Q for U...
I need to build an allocator for my objects, but! the trick is that:

* Allocator would manage his own MemAlloc And the MemFree (like dhu)
* One class could use a few types of allocators (meaning allocator is
not a static member of the class).
* I want the minimal overhead on a programmer, meaning that once he
attached an allocator to an object he wont need to remember what
allocator he attached (fire and forget)

* I could overload new and delete and use the allocator within them

One solution was makin the allocator a member of an object BUT new and
delete are defined as static functions and could only use a static
members. once i'll attach an allocator to an object all objects of the
type will use the same allocator... BAD (think what will happen if i
allocate an object with one allocator and free it with another)

Another solution was adding the allocator to the new and delete
operators, two major problems
1) i could live with specifing the allocator as an argument in the new
operator but, in the delete? two much overhead
2) the overloaded deltet doesnt work! i call it delete(new Allocator())
Object; and it redirects to the normal delete!

I think u got my drift ... its more of a design problem
I'll be happy to hear your thoughts
This FAQ gives a handy way of using custom memory allocation for
objects:

http://www.parashift.com/c++-faq-lit...html#faq-11.14

As for allocators, in the terminology of the STL, that means an object
that a container (e.g. std::vector) uses to allocate memory for its
containees. Since in the STL, the container is responsible for creating
and destroying them and the allocator's type is specified at
compile-time as a template parameter, there is less risk that the
object will be deleted by some other allocator.

As for overloaded delete not working, it should. If you consult the
aforementioned FAQ and still can't get it to work, post a minimal by
complete sample that demonstrates the problem (see
http://www.parashift.com/c++-faq-lit....html#faq-5.8).

Cheers! --M

Jan 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: regisser | last post by:
I have a quastion for the C++ professionals and members of the C++ standartization commetee. As i know C++ standart requires an allocator to be a templated parameter in every STL container....
18
by: Mark A. Gibbs | last post by:
I'm having yet another headache with making a standard allocator. What behaviour should be expected from the assigment operator? When would it be called? Why is it there at all, when you can't...
6
by: Ares Lagae | last post by:
Hello, I am trying to create a container the stl way, and I have a couple of questions. The code of the container in question can be found at ...
15
by: natespamacct | last post by:
Hi All, I'm not sure if I'm dealing with a C++ question or a compiler question, so please forgive me if I'm asking in the wrong spot. If so, maybe someone can direct me to more appropriate spot....
3
by: yasmin | last post by:
I am dealing with internal memory fragmentation issues in my program (C++ program on freeBSD). It involves a large number of fixed-size structures. For example for my records which are typically...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.