MCPcopy Create free account
hub / github.com/anjo76/angelscript / Reserve

Method Reserve

sdk/add_on/scriptarray/scriptarray.cpp:673–705  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

671}
672
673void 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
707void CScriptArray::Resize(asUINT numElements)
708{

Callers 1

Calls 1

SetExceptionMethod · 0.80

Tested by

no test coverage detected