home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.os.os2.programmer:4352 comp.lang.c:12592
- Path: sparky!uunet!kithrup!hoptoad!decwrl!elroy.jpl.nasa.gov!swrinde!gatech!rutgers!njitgw.njit.edu!hertz.njit.edu!dic5340
- From: dic5340@hertz.njit.edu (David Charlap)
- Newsgroups: comp.os.os2.programmer,comp.lang.c
- Subject: Re: malloc causes a segmentation violation!?
- Message-ID: <1992Aug20.211646.14022@njitgw.njit.edu>
- Date: 20 Aug 92 21:16:46 GMT
- References: <1992Aug19.155648.6210@funet.fi> <1992Aug19.171317.9312@bnr.ca> <chuckb.714275722@milton>
- Sender: news@njit.edu
- Organization: New Jersey Institute of Technology, Newark, N.J.
- Lines: 31
- Nntp-Posting-Host: hertz.njit.edu
-
- In article <chuckb.714275722@milton> chuckb@milton.u.washington.edu (Chuck Bass) writes:
- >I am wondering if this is common among people who program in C. I
- >haven't been programing in multiple environments (TurboC and an SGI
- >workstation only). I write code that runs on both and do *lots* of
- >dynamic memory allocation. Is this a bad habit, terrible habit, good
- >habit? It seems to me that a general program should be able to
- >adjust to the required size dynamically.
-
- Bugs in the compiler/library aside, C programs can and should use
- malloc(). Malloc, free and realloc are all defined by K&R in their
- ANSI-C book. It's part of <stdlib.h>
-
- C++ programs, however, should not. They should use the "new" operator
- for dynamically allocating and deallocating storage.
-
- For instance:
-
- To allocate an integer:
- pInteger = new int;
-
- To allocate space for 100 integers:
- pInteger = new int[100];
-
-
- and so on.
-
- --
- |) David Charlap "I don't even represent myself
- /|_ dic5340@hertz.njit.edu sometimes so NJIT is right out!.
- ((|,)
- ~|~ Hi! I am a .signature virus, copy me into your .signature file.
-