home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!microsoft!wingnut!pauljo
- From: pauljo@microsoft.com (Paul Johns)
- Subject: Re: using new
- Message-ID: <1993Jan12.002045.23805@microsoft.com>
- Date: 12 Jan 93 00:20:45 GMT
- Organization: Microsoft Corp., Redmond, Washington, USA
- References: <1993Jan8.171950.22884@news.columbia.edu>
- Lines: 32
-
- In article <1993Jan8.171950.22884@news.columbia.edu> ae2@cunixa.cc.columbia.edu wrote:
- >
- > I am in the process of porting a C program into C++ and
- > learning a lot about C++. I am trying to find an equivalent C++
- > construct for the following malloc command:
- >
- >
- > ptr = (TypeCast *) malloc( LENGTH(n));
-
- No reason not to continue using malloc here....you can intermix
- malloc and new in the same program provided that you free all
- blocks allocated with malloc by using free and that you delete
- all blocks allocated by using new with delete.
-
- > where Length(n) is a macro that will return the n times of the
- > desired object size. I have tried the following statement using new
- > but for no avail:
- >
- >
- > ptr = (TypeCast *) new char(LENGTH(n));
-
- This statement means "allocate ONE character and initialize it
- with "LENGTH(n)".
-
- You want:
-
- ptr = (TypeCast *) new char [LENGTH(n)];
-
- instead....
-
- // Paul
-
-