Neil wrote:
> Hi,
>  Thanks for the below.
> 
> I have a linked list, and want to have it in its own heap.
> 
> I use the HeapCreate(..) to create the heap , and then use multiple
> HeapAlloc(s_hHeap,0,size);  to create the space.
> 
> if I have something like:
> class CSomeClass ; // a clas I want to have in
> 
> typedef struct{
>   int Use;
>   CSomeClass  m_Class;
>   int Another variable;
> }LinkedStruct;
> 
> HeapAlloc(s_hHeap,0,sizeof(LinkedStruct));
> 
> As this just creates the space, is there anyway I can have the class within 
> the structure to have its constructor called, and use it within the linked 
> list.
> 
> Is this possible? If so, whats the best way?

Yes, you need to use the placement new operator, like:

void * mem = get_memory_ptr();
if (mem)
{
        MyObject * obj = new( mem ) MyObject();
        // *obj is constructed within the memory location pointed to by mem
}

Ehsan


_______________________________________________
msvc mailing list
[email protected]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for 
subscription changes, and list archive.

Reply via email to