Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* how to determine the size of dynamic array??
@ 2003-08-06 23:30 Tylenol
  2003-08-07 14:02 ` Ed Vogel
  0 siblings, 1 reply; 5+ messages in thread
From: Tylenol @ 2003-08-06 23:30 UTC (permalink / raw)


Hi All:
Does anyone have ideas how to determine the size of dynamic array? I
know MSVC have a function called "_msize()" which doing this kind of
job. However, I am not sure on Unix Tru64 have a similar function or
not. The most similar function I found is "mallocate()" but this
function returns the array size is always larger than original
requested size of array. Any function in Unix Tru64 doing the same job
as "_msize()"? Please Help!!!

Thanks in advance
Harley


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to determine the size of dynamic array??
  2003-08-06 23:30 how to determine the size of dynamic array?? Tylenol
@ 2003-08-07 14:02 ` Ed Vogel
  2003-08-07 20:56   ` Tylenol
  0 siblings, 1 reply; 5+ messages in thread
From: Ed Vogel @ 2003-08-07 14:02 UTC (permalink / raw)



    If by "dynamic array" you mean what the C Standard calls
    "variable length array",  the C compiler on Tru64 has this
    support, and you just use the sizeof() operator to get the
    size of the array.  For example:

    int x = 5;
    main() {
        int a[x];   /* Declare a varible length array */
        printf("size is %d\n",sizeof(a));
    }

    will emit: "size is 20" when run.

    Ed Vogel
    HP C Engineering

"Tylenol" <harley_chan@hotmail.com> wrote in message
news:becbc481.0308061530.22556518@posting.google.com...
| Hi All:
| Does anyone have ideas how to determine the size of dynamic array? I
| know MSVC have a function called "_msize()" which doing this kind of
| job. However, I am not sure on Unix Tru64 have a similar function or
| not. The most similar function I found is "mallocate()" but this
| function returns the array size is always larger than original
| requested size of array. Any function in Unix Tru64 doing the same job
| as "_msize()"? Please Help!!!
|
| Thanks in advance
| Harley




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to determine the size of dynamic array??
  2003-08-07 14:02 ` Ed Vogel
@ 2003-08-07 20:56   ` Tylenol
  2003-08-08 14:00     ` Ed Vogel
  0 siblings, 1 reply; 5+ messages in thread
From: Tylenol @ 2003-08-07 20:56 UTC (permalink / raw)


Thanks Ed Vogel,
For dynamic array, the block of memory is allocated by "malloc()" such
as

int *a = malloc(16);

When I use sizeof(a), it gives me 8 not 4. Anything wrong?? or I use
the "sizeof()" function in wrong way.

some correction in the previous message: the "mallocate()" should be
"mallocblksize():


Thanks
Harley


"Ed Vogel" <edward.vogel_nospam@hp.com> wrote in message news:<6_sYa.1689$K_4.849@news.cpqcorp.net>...
> If by "dynamic array" you mean what the C Standard calls
>     "variable length array",  the C compiler on Tru64 has this
>     support, and you just use the sizeof() operator to get the
>     size of the array.  For example:
> 
>     int x = 5;
>     main() {
>         int a[x];   /* Declare a varible length array */
>         printf("size is %d\n",sizeof(a));
>     }
> 
>     will emit: "size is 20" when run.
> 
>     Ed Vogel
>     HP C Engineering
> 
> "Tylenol" <harley_chan@hotmail.com> wrote in message
> news:becbc481.0308061530.22556518@posting.google.com...
> | Hi All:
> | Does anyone have ideas how to determine the size of dynamic array? I
> | know MSVC have a function called "_msize()" which doing this kind of
> | job. However, I am not sure on Unix Tru64 have a similar function or
> | not. The most similar function I found is "mallocate()" but this
> | function returns the array size is always larger than original
> | requested size of array. Any function in Unix Tru64 doing the same job
> | as "_msize()"? Please Help!!!
> |
> | Thanks in advance
> | Harley


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to determine the size of dynamic array??
  2003-08-07 20:56   ` Tylenol
@ 2003-08-08 14:00     ` Ed Vogel
  2003-08-20 17:59       ` Jerry Feldman
  0 siblings, 1 reply; 5+ messages in thread
From: Ed Vogel @ 2003-08-08 14:00 UTC (permalink / raw)



"Tylenol" <harley_chan@hotmail.com> wrote in message
news:becbc481.0308071256.2534600a@posting.google.com...
| Thanks Ed Vogel,
| For dynamic array, the block of memory is allocated by "malloc()" such
| as
|
| int *a = malloc(16);
|
    In this case you don't really have a varible-length array, you simply
have
    dynamic storage that you chose to reference as an array.

| When I use sizeof(a), it gives me 8 not 4. Anything wrong?? or I use
| the "sizeof()" function in wrong way.

    When you say sizeof(a), this will give you the size of a, which
    is a pointer.  A pointer on Tru64 is 8 bytes.

    I do not know of a way to find the size of the malloc'ed storage.

    Ed




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to determine the size of dynamic array??
  2003-08-08 14:00     ` Ed Vogel
@ 2003-08-20 17:59       ` Jerry Feldman
  0 siblings, 0 replies; 5+ messages in thread
From: Jerry Feldman @ 2003-08-20 17:59 UTC (permalink / raw)


On Fri, 08 Aug 2003 14:00:50 GMT
"Ed Vogel" <edward.vogel_nospam@hp.com> wrote:

> I do not know of a way to find the size of the malloc'ed storage.
Common Ed, sure you do. Just look into the malloc header. Rather
non-portable, but it works. 

-- 
Jerry Feldman <gaf-nospam-at-blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-08-20 17:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-06 23:30 how to determine the size of dynamic array?? Tylenol
2003-08-07 14:02 ` Ed Vogel
2003-08-07 20:56   ` Tylenol
2003-08-08 14:00     ` Ed Vogel
2003-08-20 17:59       ` Jerry Feldman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox