MCPcopy Create free account
hub / github.com/CytopiaTeam/Cytopia / Reserve

Method Reserve

external/as_add_on/scriptarray/scriptarray.cpp:611–643  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

609}
610
611void CScriptArray::Reserve(asUINT maxElements)
612{
613 if( maxElements <= buffer->maxElements )
614 return;
615
616 if( !CheckMaxSize(maxElements) )
617 return;
618
619 // Allocate memory for the buffer
620 SArrayBuffer *newBuffer = reinterpret_cast<SArrayBuffer*>(userAlloc(sizeof(SArrayBuffer)-1 + elementSize*maxElements));
621 if( newBuffer )
622 {
623 newBuffer->numElements = buffer->numElements;
624 newBuffer->maxElements = maxElements;
625 }
626 else
627 {
628 // Out of memory
629 asIScriptContext *ctx = asGetActiveContext();
630 if( ctx )
631 ctx->SetException("Out of memory");
632 return;
633 }
634
635 // As objects in arrays of objects are not stored inline, it is safe to use memcpy here
636 // since we're just copying the pointers to objects and not the actual objects.
637 memcpy(newBuffer->data, buffer->data, buffer->numElements*elementSize);
638
639 // Release the old buffer
640 userFree(buffer);
641
642 buffer = newBuffer;
643}
644
645void CScriptArray::Resize(asUINT numElements)
646{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected