home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky vmsnet.internals:1439 vmsnet.misc:911 comp.lang.c:14814
- Path: 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
-
- 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
-