| 21 | |
| 22 | // Allocate space for an array and initialise its elements to null expressions |
| 23 | void ArrayHandle::Allocate(size_t numElements) THROWS(GCodeException) |
| 24 | { |
| 25 | #if CHECK_HEAP_LOCKED |
| 26 | Heap::heapLock.CheckHasWriteLock(); |
| 27 | #endif |
| 28 | Heap::IndexSlot * const slot = Heap::AllocateHandle(); |
| 29 | Heap::StorageSpace * const space = Heap::AllocateSpace(sizeof(ArrayStorageSpace) + numElements * sizeof(ExpressionValue)); |
| 30 | slot->storage = space; |
| 31 | if (space->length < sizeof(ArrayStorageSpace) + numElements * sizeof(ExpressionValue)) |
| 32 | { |
| 33 | Heap::DeleteSlot(slot); |
| 34 | throw GCodeException("Array too large"); |
| 35 | } |
| 36 | |
| 37 | ArrayStorageSpace * const aSpace = reinterpret_cast<ArrayStorageSpace*>(space); |
| 38 | aSpace->count = numElements; |
| 39 | for (size_t i = 0; i < numElements; ++i) |
| 40 | { |
| 41 | new (&aSpace->elements[i]) ExpressionValue; |
| 42 | } |
| 43 | slotPtr = slot; |
| 44 | } |
| 45 | |
| 46 | // Assign an element without making the array unique first |
| 47 | void ArrayHandle::AssignElement(size_t index, ExpressionValue &val) THROWS(GCodeException) |
nothing calls this directly
no test coverage detected