OpenAmiga (707/959)

From:Jean-Michel Forgeas
Date:27 Aug 2000 at 10:33:49
Subject:Re: AMIOPEN: Object allocated on stack - init and/or open

Thanks for your reply. I would like to add more detail about my first
question :

> > Question 1:
> > Since the _new method for objects is the allocator, is it (will it be)
> > correct to reserve the object size on the stack then call its init
method to have
> > a fully fonctional instance ?
>
> NO! Bad monkey!
> [...] Allocating on the stack as you describe
> will almost guarantee that the class object gets overwritten with
> arbitrary data. [...]
> Jesse

So it doesn't work the way as before : before if we use automatic
variables/buffers into a block, we didn't have the stack overwritten
with other data.
So please, could you confirm that this example in c will not work :
//--- Start of block or function
{
//--- Allocate space on stack, get a pointer and init it (macro?)
char intance_buf[MYINSTANCE_SIZE];
myobject *obj = (myobject*) instance_buf;
call obj,init...
//--- Use the pointer as an object
............
//--- Free object resources before changing stack use (macro?)
call obj,deinit...
}

This would allow to use light elate objects in c or asm as in c++,
without having to allocate memory (quick, no fail).
And (if this example works) what is the limitation with the type
of stack memory compared to the use of allocdata and allocdef ?

Thanks !

Best regards,
Jean-Michel Forgeas

Subscribe/Unsubscribe: open-request@amiga.com
Amiga FAQ: http://www.amiga.com/faq.html