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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tristan Wibberley

    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.


  • Victor Bazarov

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

    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


    Comment

    • James Kanze

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

      On Feb 13, 11:19 pm, Tristan Wibberley <maihem-...@maihem.orgw rote:
      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:james.kan ze@gmail.com
      Conseils en informatique orientée objet/
      Beratung in objektorientier ter Datenverarbeitu ng
      9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

      Comment

      • Default User

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

        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

        Comment

        Working...