Hi,
you can place Objects into given memory space using the "new placement
syntax" (google-ready).
You have simply to add the following "method" to a class (or struct):
class Placeable {
public:
//...
void* operator new( size_t, void* buf ) { return buf; }
//...
};
this "method" is the overriden new-operator with placement semantics.
For instantiation you have to write:
extern void* address; // your memory section
Placeable* placed = new (address) YourStruct(/*constructor arguments if
any*/); // constructor with arguments
Placeable* placed = new (address) YourStruct; // constructor without
arguments
note you must not use the delete-operator on the object created by
overriden new.
for clenup (if needed) you have to define a destructor that you call
explicitly:
placed->Placeable::~Placeable();
Good luck,
Wolf Peuker
Ruchika Singh schrieb:
>Hi:
>
>I am fairly new to C++. I have in my ld script defined a memory section,
>".my_mem_section". How can I force one of my global C++ object to be allocated
>memory in this section when instantiated??
>
>Thanks in advance
>-R.
>
>
>
>-------------------------------------------------------
>SF.Net email is sponsored by:
>Tame your development challenges with Apache's Geronimo App Server. Download
>it for free - -and be entered to win a 42" plasma tv or your very own
>Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
|