Using new operator to allocate arrays dynamically

I've been working on interfacing my Ti-83 with my Arduino and had trouble with dynamically allocating an array. I tried including the new operator function I found somewhere but that didn't look right and only worked once (it failed when trying to allocate a second array after supposedly deleting the old one).

I don't think the code I used was correct but I'm not sure how to rewrite it.

void * operator new(size_t size);
void * operator new[](size_t size);
void operator delete(void * ptr);
void operator delete[](void * ptr);

void * operator new(size_t size)
{
  return malloc(size);
}

void operator delete(void * ptr)
{
  free(ptr);
}
 
void * operator new[](size_t size)
{
    return malloc(size);
}

void operator delete[](void * ptr)
{
    free(ptr);
}

To my eyes it looks like the new[] operator doesn't do anything more than the new operator does, in other words it allocates a single instance of the object (in my case an unsigned int) but doesn't allocate anything for the rest of the array. It seems like it should have a for loop in there but it seems to only have a single argument.

What I'd like to do is this:

packetData = new unsigned int[packetHeader[2]];

Followed later by this:

delete[] packetData;

Or whatever the proper syntax is. In fact, this may be my main problem. Is that the correct syntax? Or do I need to provide the size again (now that I think about it I think I would).

Like I said, the first time through it seemed to work fine, the second time, however, it just stopped when it tried to new another array.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230935955

I don't see how that relates to arrays though. Seems to be just single objects. I can do single objects just fine. In fact it apparently did a single array just fine but crashed when it tried to make the second array. Now it could be that the first array didn't actually work and it was actually overwriting some portion of memory, it could also be that it did actually work but that my delete call didn't.

The problem with arrays is that the addresses have to be consecutive. myArray[1] is equivalent to *(myArray+1) and myArray[367] is equivalent to *(myArray+367) which means unless it can be guaranteed that subsequent calls to malloc will return consecutive memory addresses 100% of the time I can't just for loop it.

What size arrays are you trying to allocate?