Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!prls!pyramid!nsc!daisy!misha From: misha@daisy.UUCP (Mike Umansky) Newsgroups: net.unix,net.unix-wizards,net.arch,net.lang.c Subject: get size of malloc'd object Message-ID: <165@daisy.UUCP> Date: Thu, 12-Jun-86 18:22:27 EDT Article-I.D.: daisy.165 Posted: Thu Jun 12 18:22:27 1986 Date-Received: Sun, 15-Jun-86 04:10:29 EDT Distribution: net Organization: Daisy Systems Corp., Mountain View, Ca Lines: 30 Xref: linus net.unix:7437 net.unix-wizards:15318 net.arch:3122 net.lang.c:8615 I have a need in my application to find the size of a previously malloc'd object (maybe an array or structure). For example, one routine may allocate some array or just one big chunk of memory and pass a pointer to the chunk to another routine. This other routine now needs to know the size of the area pointed to by this pointer. Also, this other routine has no idea about the structure of this area and doesn't even care. Now, the question, how can this other routine get the size of the area pointed to by passed pointer. Would (sizeof(*ptr)) work or will it just give me the size of the pointer type? Another possibility would be to write a routine which would scan malloc's allocation array and try to match the pointers; then the size is easily obtained. Any help and comments on this would be greately appreciated. Either post your answers or mail them directly please. Thanks for consideration. -- -- NAME: Michael Umansky (misha) E-MAIL: ucbvax!hplabs!nsc!daisy!misha WORK: Daisy Systems Corp. 700B Middlefield Road Mountain View, CA 94039-7006 (415) 960-7166 (work) HOME: 94 Cassia Ct. Hayward, CA 94544 (415) 886-4805 (home)