MCPcopy Create free account
hub / github.com/chronoxor/FastBinaryEncoding / Allocate

Method Allocate

projects/CSharp/Proto/com.chronoxor.fbe.cs:151–173  ·  view source on GitHub ↗

Allocate memory in the current buffer and return offset to the allocated memory block

(long size)

Source from the content-addressed store, hash-verified

149
150 // Allocate memory in the current buffer and return offset to the allocated memory block
151 public long Allocate(long size)
152 {
153 Debug.Assert((size >= 0), "Invalid allocation size!");
154 if (size < 0)
155 throw new ArgumentException("Invalid allocation size!", nameof(size));
156
157 long offset = Size;
158
159 // Calculate a new buffer size
160 long total = _size + size;
161
162 if (total <= Capacity)
163 {
164 _size = total;
165 return offset;
166 }
167
168 byte[] data = new byte[Math.Max(total, 2 * Capacity)];
169 Array.Copy(_data, 0, data, 0, _size);
170 _data = data;
171 _size = total;
172 return offset;
173 }
174
175 // Remove some memory of the given size from the current buffer
176 public void Remove(long offset, long size)

Callers

nothing calls this directly

Calls 1

CopyMethod · 0.45

Tested by

no test coverage detected