From: | Robert Templeton |
Date: | 14 Aug 2000 at 15:46:41 |
Subject: | Re: Passing a ptr |
--- In amiga-c@egroups.com, "Damir Arh" <damir.arh@t...> wrote:
> Hello!
>
> > Ok, I tried the following but it doesn't work. I am assuming I am
> > not addressing the variables in the correct way within the
funtion.
> > Here's what I am doing:
>
> Well, you mentioned in the next mail that you stopped trying to do
it this
> way, but I'd still like to warn you about something:
>
> > if (*array = (mystruct **) AllocVec ( arraysize * sizeof
(mystruct)))
>
> Shouldn't you be using 'sizeof(mystruct *)' as you are actually
allocating
> an array of pointers to mystruct and not an array of mystructs if I
am not
> mistaking.
>
> Kind regards
> --
> Damir Arh, programmer
> Windows and Amiga developer
> Visit: http://damir.gajba.net/
Damir is correct. Otherwise you are allocating an array of mystruct
and then trying to allocate another array of mystruct pointed to by
the structure. Won't work. This would definitely cause all sorts of
caustic behavior (including memory leaks). Hope that was just a
typing transference error :)
Get a good book on algorithms in C (covering arrays, lists, heaps,
sorts, stacks, and such). This kind of aggrevation can be avoided
completely because the template routines are laid out for you with no
need for trial and error.
Robert Templeton