C (266/301)

From:Rod Schnell
Date:17 Aug 99 at 05:43:08
Subject:Re: Structure Arrays

From: Rod Schnell <rodsch@telusplanet.net>

Hello Christian

On 16-Aug-99, Christian Hattemer wrote:
> From: Christian Hattemer <Chris@heaven.riednet.wh.tu-darmstadt.de>
>
> Hi,
>
> I think I've found an easier solution for the problem I had with dynamic
> structs. I'm going to pass in the sizeof() of the whole struct and all
> offsets with offsetof().
>
> The only problem left is: How do I create an array of structs dynamically?

GAD_MAX =10;

ULONG i = 0;

struct Gadget **gadgets; // gadget pointer array

gadgets = AllocVec( (sizeof(struct Gadget *) * (GAD_MAX)), MEMF_ANY |
MEMF_CLEAR)

while(i < GAD_MAX)
{
gadgets[i++] = AllocVec(sizeof(struct Gadget), MEMF_ANY | MEMF_CLEAR)
}

Depending on exactly what you're doing, it maybe be better to use a list.

Regards

Rod