473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

new vs *alloc (Was: difference between calloc() and malloc())


On Wed, 2008-02-13 at 15:42 -0500, Victor Bazarov wrote:
Well, malloc and calloc are just 'new char[]' and 'new char[]()'.
They don't "reserve raw memory" since there is no "raw memory" in
C++.
does new char[] give memory aligned appropriately for any type?

--
Tristan Wibberley

Any opinion expressed is mine (or else I'm playing devils advocate for
the sake of a good argument). My employer had nothing to do with this
communication.
Feb 13 '08 #1
3 3901
Tristan Wibberley wrote:
On Wed, 2008-02-13 at 15:42 -0500, Victor Bazarov wrote:
>Well, malloc and calloc are just 'new char[]' and 'new char[]()'.
They don't "reserve raw memory" since there is no "raw memory" in
C++.

does new char[] give memory aligned appropriately for any type?
See 5.3.4/10. As I read it, it does. But do check.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 13 '08 #2
On Feb 13, 11:19 pm, Tristan Wibberley <maihem-...@maihem.orgwrote:
On Wed, 2008-02-13 at 15:42 -0500, Victor Bazarov wrote:
Well, malloc and calloc are just 'new char[]' and 'new char[]()'.
They don't "reserve raw memory" since there is no "raw memory" in
C++.
does new char[] give memory aligned appropriately for any type?
Yes. IMHO, however, it still gives the wrong signal to a reader
of the code. You don't want an array of char, you want raw
memory. (The standard just calls it "storage", but "raw memory"
is the usual term in less formal circles.) The standard also
defines a new expression as doing to things: calling an
allocator function to allocate the (raw) memory, and
initializing the object(s) in that memory. The "name" of that
allocator function is "operator new()". And that's exactly what
I use if I need raw memory.

Note that in C++, the only thing you can do with raw memory *is*
initialize it (or free it without using it).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Feb 14 '08 #3
James Kanze wrote:

Technical note James. One of the the unlovely features of Google Groups
is that changing the subject line (at least by default) starts a new
thread. Hence this message bounced out of the ongoing original thread
into its own.

Brian
Feb 14 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: MK | last post by:
I am a newbie. Please help. The following warning is issued by gcc-3.2.2 compiler (pc Linux): ================================================================== read_raw_data.c:51: warning:...
21
by: Bryan Bullard | last post by:
Hi, Is there a standard way to validate if a pointer points to memory that was allocated by malloc? TIA
8
by: venkatesh | last post by:
hai to everybody, i am having doubt in difference between the malloc and calloc function. please tell where to use and when to use those functions?
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.