New? No way!

Hello all.
I'm currently developing for XBox, and I have some problems with the "new" operator.
Fact is, it's quite good for large chunks of memory, but for small data structure has way too much overhead (IMO).

For instance, if I write:
[code]
char ch=new char;
[/code]

I get:
1) the one char I asked for
2) 15 bytes for padding the "structure" to 16 bytes
3) 16 bytes of "memory descriptor", to let the "delete" operator do its job.

Allocating small memory blocks causes an horrific memory fragmentation, not to mention that I am wasting tons of memory, and 64 MB aren't *that* much anyway, these days.

Anyone knows how to get less overhead than that?
Thanks in advance.

Comments

  • : Hello all.
    : I'm currently developing for XBox, and I have some problems with the "new" operator.
    : Fact is, it's quite good for large chunks of memory, but for small data structure has way too much overhead (IMO).
    :
    : For instance, if I write:
    : [code]
    : char ch=new char;
    : [/code]
    :
    : I get:
    : 1) the one char I asked for
    : 2) 15 bytes for padding the "structure" to 16 bytes
    : 3) 16 bytes of "memory descriptor", to let the "delete" operator do its job.
    :

    Why not try overloading the 'new' operator for char then?
  • Hi Genjuro
    Well, 'new' will always do this. And much worse if it had the chance i'm sure. The memory descriptor may only appear in debubg builds but the padding is most probably due to an optimisation that is alterable in the compiler options ( maybe ) Anyway, you are doing well in actualy knowing what 'new' is realy doing in the first place and thats the valuable lesson i think.
    The top tip is, use it never Or when speed is not an issue. Like level initialisation. That has a good chance of being only my opinion btw :). Xbox/Pc has wonderfull cpu of monumental girth, as well as memory management unit of similar size. This will chew up the overhead and hide it from you, but if you need to develop cross platform then you can kiss goodbye the performance on every console :( If at all possible, pre-allocate all your stuff before runtime. Or, pre-allocate a huge chunk and write your own memory management routine that uses that chunk. Otherwise, the top tip is dont use it. That may seem a bit harsh but welcome to games dev :D

    : I'm currently developing for XBox, and I have some problems with the "new" operator.
    : Fact is, it's quite good for large chunks of memory, but for small data structure has way too much overhead (IMO).
    :
    : For instance, if I write:
    : [code]
    : char ch=new char;
    : [/code]
    :
    : I get:
    : 1) the one char I asked for
    : 2) 15 bytes for padding the "structure" to 16 bytes
    : 3) 16 bytes of "memory descriptor", to let the "delete" operator do its job.
    :
    : Allocating small memory blocks causes an horrific memory fragmentation, not to mention that I am wasting tons of memory, and 64 MB aren't *that* much anyway, these days.
    :
    : Anyone knows how to get less overhead than that?
    : Thanks in advance.
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories