Skip to main content
GameDev.net gamedev.net
🔒 Locked

Static allocated smart pointer

Started by programering Dec 19, 2010 at 11:26 AM 3 replies 2k views
Original Post
programering
programering
I've got an idea to invent a smart pointer for static allocated objects.

I need it because I want the pointer itself to be reseted to NULL when the source it points to become deallocated. So is it possible to detect its deallocation.
Zakwayda
Zakwayda
What language(s) do you have in mind? Also, when and under what circumstances does the statically allocated object get deallocated? (And what precisely do you mean by statically allocated?)

Can you give an example?
Zahlman
Zahlman
Quote:
Original post by programering
I've got an idea to invent a smart pointer for static allocated objects.

I need it because I want the pointer itself to be reseted to NULL when the source it points to become deallocated. So is it possible to detect its deallocation.


... And when and why, exactly, are you expecting a statically allocated object to be deallocated? And why do you need to do something in response to that?
programering
programering
Quote:
Original post by jyk
What language(s) do you have in mind?

C Plus Plus of coarse.

Quote:
Original post by jyk
Also, when and under what circumstances does the statically allocated object get deallocated? (And what precisely do you mean by statically allocated?)

Can you give an example?


For example if the object to be used for my smart pointer(ObjectToBeUsed) is an actual instance member within another object(SourceObject). That's what I thought statically allocation was(If that's right?).

Like this:
class SourceObject{    ObjectToBeUsed testSource; // Its origin is here.};


So when a SourceObject instance is deallocated, a such smart pointer of mine with this testSource as target shall be notified and set its internal raw pointer to NULL.

Is there a way to check if an address is deallocated?
Decrius
Decrius
It's only static if you put the keyword "static" in front of it, which essentially makes it a global.

What you want is composition, one object containing another object.

If you want to be notified of deallocation, implement a destructor, it'll be called upon destruction.
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.