#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    61
    Rep Power
    12

    Efficient memory management?


    I have created a library an C, and an equivalent i C# (for the .NET platform). To my surprise, the C# version is faster!

    I have tracked this strange behavior to memory allocation, which for some reason is much faster in C#.

    I have made some optimizations which reduced number of calls to malloc() in my C code, and that helped. But I am convinced that a further improvement is possible if malloc() could be replaced with a faster memory allocation method.

    Does anybody know about a library for more efficient memory management than malloc() and free()? Or maybe an algorithm to somehow allocate in advance and realloc if needed?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    In C++, you can use "new" and "delete". I don't know if they're more efficient or not, but from the descriptions of those operators, they seem like they would be.
    Last edited by 7stud; March 8th, 2003 at 08:22 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    ISRAEL
    Posts
    35
    Rep Power
    14
    you can use the API functions (read the MSDN for furthur info):
    GlobalAlloc, VirtualAlloc/Ex, HeapAlloc...
    that should probably help.

    Please let us know about it.
    "Gravitation can NOT be responsible for people falling in Love"
    (one of the most significant characters in the history, can you guess?)

    Gmorph.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    61
    Rep Power
    12
    My library is not only for windows, så I cannot use win32 specific API.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    ISRAEL
    Posts
    35
    Rep Power
    14
    than you have a problem there huston :D

    it is common knowledge that memory allocation takes relatively a lot of time.
    it is a good advice to do that as few as you can
    "Gravitation can NOT be responsible for people falling in Love"
    (one of the most significant characters in the history, can you guess?)

    Gmorph.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    61
    Rep Power
    12
    If memory allocation can be fast in .NET, then there must be some way to make it fast in C - I would guess that some kind of memory pooling could be used?

IMN logo majestic logo threadwatch logo seochat tools logo