| 671 | } |
| 672 | |
| 673 | void CScriptArray::Reserve(asUINT maxElements) |
| 674 | { |
| 675 | if( maxElements <= buffer->maxElements ) |
| 676 | return; |
| 677 | |
| 678 | if( !CheckMaxSize(maxElements) ) |
| 679 | return; |
| 680 | |
| 681 | // Allocate memory for the buffer |
| 682 | SArrayBuffer *newBuffer = reinterpret_cast<SArrayBuffer*>(userAlloc(sizeof(SArrayBuffer)-1 + elementSize*maxElements)); |
| 683 | if( newBuffer ) |
| 684 | { |
| 685 | newBuffer->numElements = buffer->numElements; |
| 686 | newBuffer->maxElements = maxElements; |
| 687 | } |
| 688 | else |
| 689 | { |
| 690 | // Out of memory |
| 691 | asIScriptContext *ctx = asGetActiveContext(); |
| 692 | if( ctx ) |
| 693 | ctx->SetException("Out of memory"); |
| 694 | return; |
| 695 | } |
| 696 | |
| 697 | // As objects in arrays of objects are not stored inline, it is safe to use memcpy here |
| 698 | // since we're just copying the pointers to objects and not the actual objects. |
| 699 | memcpy(newBuffer->data, buffer->data, buffer->numElements*elementSize); |
| 700 | |
| 701 | // Release the old buffer |
| 702 | userFree(buffer); |
| 703 | |
| 704 | buffer = newBuffer; |
| 705 | } |
| 706 | |
| 707 | void CScriptArray::Resize(asUINT numElements) |
| 708 | { |
no test coverage detected