Topic: Malloc with align


Author: petebecker@acm.org (Pete Becker)
Date: Wed, 25 Aug 2004 23:45:32 GMT
Raw View
Bob Hairgrove wrote:
>
> malloc() is somewhat off-topic here ... the only thing the standard
> says about malloc and free is that in a conforming implementation,
> "malloc shall not call new, and free shall not call delete" to
> allocate storage (see 20.4.6 for details).
>

It actually says a great deal more than that. Concerning <cstdlib> it
says:

 The contents are the same as the Standard C library header <stdlib.h>,
 with the following changes:

 The functions calloc(), malloc(), and realloc() do not attempt to
 allocate storage by calling ::operator new()

 The function free() does not attempt to deallocate storage by calling
 ::operator delete().

The key is that first paragraph, which tells you exactly what these
functions do.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: invalid@bigfoot.com (Bob Hairgrove)
Date: Tue, 24 Aug 2004 02:53:40 GMT
Raw View
On Mon, 23 Aug 2004 20:01:47 GMT, dwalker07@snet.net (Daryle Walker)
wrote:

>Besides the size of a type, the memory alignment requirements are
>important.  Shouldn't functions like std::malloc take in a size and
>alignment?  (Unless all objects can have a common alignment value and
>std::malloc just uses that one.)
>
>This could be discussed with the C guys too.  Of course, then we would
>need a new function name.

Alignment requirements are left as implementation-defined in the C++
standard (see 3.9.1 and 5.3.4, paragraph 10). This is because C++
needs to be portable across many different hardware platforms and
operating systems. Your compiler will have certain commands (such as
#pragma align) which you can use if you need to specify a different
alignment than the default.

malloc() is somewhat off-topic here ... the only thing the standard
says about malloc and free is that in a conforming implementation,
"malloc shall not call new, and free shall not call delete" to
allocate storage (see 20.4.6 for details).

So maybe you should discuss this with the "C guys" (and gals<g>).

--
Bob Hairgrove
NoSpamPlease@Home.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: dwalker07@snet.net (Daryle Walker)
Date: Mon, 23 Aug 2004 20:01:47 GMT
Raw View
Besides the size of a type, the memory alignment requirements are
important.  Shouldn't functions like std::malloc take in a size and
alignment?  (Unless all objects can have a common alignment value and
std::malloc just uses that one.)

This could be discussed with the C guys too.  Of course, then we would
need a new function name.

--
Daryle Walker
Mac, Internet, and Video Game Junkie
dwalker07 AT snet DOT net

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: petebecker@acm.org (Pete Becker)
Date: Tue, 24 Aug 2004 00:38:57 GMT
Raw View
Daryle Walker wrote:
>
> Besides the size of a type, the memory alignment requirements are
> important.  Shouldn't functions like std::malloc take in a size and
> alignment?  (Unless all objects can have a common alignment value and
> std::malloc just uses that one.)
>

malloc returns a block of memory that's suitably sized for any type.
Always has, always will. <g>

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]