----- Original Message -----
From: "Sam Tregar" <[EMAIL PROTECTED]>
To: "Sisyphus" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, July 17, 2002 11:23 AM
Subject: Re: sizeof dynamically allocated array


> On Tue, 16 Jul 2002, Sisyphus wrote:
>
> > How does one retrieve the size of (number of elements contained in) such
an
> > item ?
>
> You don't.  C arrays are just pointers and don't carry size information.
> If your array is a NULL-terminated C string then you can use strlen(), but
> that won't work for numeric data.  Mostly you'll just have to pass the
> length of the array around with the array.
>
> Note that this is more of a C programming question than an Inline
> question.  You might get a better answer in a C programming forum.
>

Hmmm ..... not so sure about that last point, but I'm not about to debate
the issue :-)

The function '_msize' (malloc.h) enables one to get the size of an array
that has been created with 'malloc' and altered with 'realloc'. Since
'Renew' is the xsub interface to 'realloc' I thought there might be some way
of accessing the info from Inline. (Simply including malloc.h in inline
scripts creates syntax errors, so '_msize' is out of the question. I tried
using the '_msize' function without including malloc.h - which compiles and
runs ok, but doesn't yield the correct answer.)

I've been keeping track of the size as Sam and !c suggest, but there are
times (usually when trying to correct programming errors) that it would be
handy to be able to directly check and see how much memory has been
allocated to a particular array.

Anyway, it's heartening to know that I haven't been missing anything
*really* obvious :-)

Thanks !c, thanks Sam.

Cheers,
Rob

Reply via email to