Article View: vmsnet.internals
Article #365Re: malloc() as a user defined function
From: David L. Cathey
Date: Fri, 09 Oct 1992 23:30
Date: Fri, 09 Oct 1992 23:30
29 lines
1635 bytes
1635 bytes
In article <Bvv6pH.Gzy@cs.psu.edu>, ytang@red.crayola.cs.psu.edu (Yuan-Ling Tang) writes:
>
> Hi netters:
>
> In programming on dynamic memory allocation, I prefer doing check on
> every malloc(). I.e.:
> ...
> However another problem arises, what if I have many distinct types
> of memory space to allocate? That is, I can't use the same type in
> calling my_malloc(). So how can I pass a type to a function?
Maybe something like this?
#define TALLOC(x) {int p ; ((p = malloc(sizeof(x)) == NULL) ? \
{perror("Malloc") ; exit(errno) } : \
p ; }
The sizeof() will resolve the type into the required number of bytes,
such that
bptr = TALLOC(struct bogus) ;
will allocate the correct size buffer, while performing the check
(I hope, I haven't tested that macro...)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
David L. Cathey |INET: davidc@montagar.com
Montagar Software Concepts |UUCP: ...!montagar!davidc
P. O. Box 260772, Plano TX 75026-0772 |Fone: (214)-618-2117
Technical Details
Message-ID:
<1992Oct9.233039.16829@montagar.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!know!cass.ma02.bull.com!think.com!sdd.hp.com!zaphod.mps.ohio-state.edu!wupost!tulane!darwin.sura.net!dtix!mimsy!prometheus!media!irscscm!bogart!aldoe!krm!mic!montagar.com!davidcReferences:
<Bvv6pH.Gzy@cs.psu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!know!cass.ma02.bull.com!think.com!sdd.hp.com!zaphod.mps.ohio-state.edu!wupost!tulane!darwin.sura.net!dtix!mimsy!prometheus!media!irscscm!bogart!aldoe!krm!mic!montagar.com!davidc From: davidc@montagar.com (David L. Cathey) Newsgroups: vmsnet.internals,vmsnet.misc,comp.lang.c Subject: Re: malloc() as a user defined function Message-ID: <1992Oct9.233039.16829@montagar.com> Date: 9 Oct 92 23:30:38 GMT References: <Bvv6pH.Gzy@cs.psu.edu> Organization: Montagar Software Concepts, Plano TX Lines: 29