Differences allocators malloc-new

This is a discussion on Differences allocators malloc-new within the C++ Programming forums, part of the General Programming Boards category; Hi Wich allocator is better to use malloc -free or new-delete?? What is the differences between them anyway? I mean ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    43

    Differences allocators malloc-new

    Hi
    Wich allocator is better to use malloc -free or new-delete?? What is the differences between them anyway? I mean in theory and not in syntax
    Thanks

  2. #2
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Quoted from: http://www.codeproject.com/cpp/pointers.asp

    Q: What's the difference between new and malloc?

    A: new is a keyword only present in C++, and is now the standard way (other than using Windows' memory allocation routines) to allocate memory. You should never use malloc within a C C++ application unless absolutely necessary. Because malloc is not designed for object-oriented features of C++, using it to allocate memory for classes will prevent the constructor of the class being called, as just one example of the problems that can arise. As a result of the problems that arise from the use of malloc and free, and because they are now for all intents and purposes obsolete, they are not discussed in any detail in this article, and I would discourage their use wherever possible.

    Q: Can I use free and delete together?

    A: You should free memory with the equivalent routine to that used to allocated it. For instance use free only on memory allocated with malloc, delete only on memory allocated with new and so on.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. malloc + segmentation fault
    By ch4 in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 03:46 PM
  2. Wierd Malloc Problem
    By mohankarthik in forum C Programming
    Replies: 11
    Last Post: 09-17-2008, 02:14 PM
  3. Is there a limit on the number of malloc calls ?
    By krissy in forum Windows Programming
    Replies: 3
    Last Post: 03-19-2006, 11:26 AM
  4. Malloc and calloc problem!!
    By xxhimanshu in forum C Programming
    Replies: 19
    Last Post: 08-10-2005, 05:37 AM
  5. malloc() & address allocation
    By santechz in forum C Programming
    Replies: 6
    Last Post: 03-21-2005, 08:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21