/** Provided for derived classes to indicate a different * size than the default. Returns whether the operation was successful. * Will leave memory untouched if it is non-null and not allocated * by this class. * @param size how much memory to allocate */ protected void allocateMemory(int size) { if (size == CALCULATE_SIZE) { // Analyze the struct, but don't worry if we can't yet do it size = calculateSize(false); } else if (size <= 0) { throw new IllegalArgumentException("Structure size must be greater than zero: " + size); } // May need to defer size calculation if derived class not fully // initialized if (size != CALCULATE_SIZE) { if (this.memory == null || this.memory instanceof AutoAllocated) { this.memory = autoAllocate(size); } this.size = size; } }
int requiredSize = array.length * size(); if (m.size() < requiredSize) { useMemory(autoAllocate(requiredSize));
/** Provided for derived classes to indicate a different * size than the default. Returns whether the operation was successful. * Will leave memory untouched if it is non-null and not allocated * by this class. * @param size how much memory to allocate */ protected void allocateMemory(int size) { if (size == CALCULATE_SIZE) { // Analyze the struct, but don't worry if we can't yet do it size = calculateSize(false); } else if (size <= 0) { throw new IllegalArgumentException("Structure size must be greater than zero: " + size); } // May need to defer size calculation if derived class not fully // initialized if (size != CALCULATE_SIZE) { if (this.memory == null || this.memory instanceof AutoAllocated) { this.memory = autoAllocate(size); } this.size = size; } }
int requiredSize = array.length * size(); if (m.size() < requiredSize) { useMemory(autoAllocate(requiredSize));