memory allocation design problem

M

ManicQin

hello ya'll.
It's my 1st post here, so be gentle.

I'm trying to build my own C++ framework (just for the fun of it), I'm
happy to say that it is a great way and I really incourge people to
learn c++ and design pattern in this way.

I decided that I need to add my own memory allocation to the frame work
- and still just for the fun of it (and because it could really speed
my system and stuff).

after contemplating on the idea I had a few thoughts:

a) I should create an interface lets say "allocatable" (or something)
and classes will inherit lets say... "allocate" function (i'm open for
new names ;))
which basicly means that i'm going to lose the constructor abillty (fix
me if i'm wrong)!

b) should I overload new?

c) how can i globalize the "allocate/new/what ever" function in a way
that a new class wont need to overload the new operator - consider that
i dont know the size of the classes.

i'll be happy to read your thoughts and any other references
 
M

mlimber

ManicQin said:
hello ya'll.
It's my 1st post here, so be gentle.

I'm trying to build my own C++ framework (just for the fun of it), I'm
happy to say that it is a great way and I really incourge people to
learn c++ and design pattern in this way.

I decided that I need to add my own memory allocation to the frame work
- and still just for the fun of it (and because it could really speed
my system and stuff).

after contemplating on the idea I had a few thoughts:

a) I should create an interface lets say "allocatable" (or something)
and classes will inherit lets say... "allocate" function (i'm open for
new names ;))
which basicly means that i'm going to lose the constructor abillty (fix
me if i'm wrong)!

You could use a virtual constructor instead:

You'll also need placement-new:

http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.10
b) should I overload new?

You can overload new on a class-by-class basis or globally, and that
may be a good idea. It really depends on the details as to what you
*should* do, however.
c) how can i globalize the "allocate/new/what ever" function in a way
that a new class wont need to overload the new operator - consider that
i dont know the size of the classes.

Compare this FAQ:

http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.14
i'll be happy to read your thoughts and any other references

Start with the FAQ, then we can talk details if you have more specific
questions.

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top