public class Malloc extends Object implements Allocator, MallocMXBean
Memory format:
SIGNATURE int64 format version magic bytesCAPACITY int64 size of the allocated memoryBASE int64 base address of the memoryBIN_0_CHUNK int64BIN_1_CHUNK int64BIN_N_CHUNK int64There are 2 types of chunks: free and occupied. Chunks are aligned to 8 byte boundary.
Free chunk format (8 byte header + 2 x 64-bit references = 24 bytes min chunk):
+--------------+--------------+
| size (int32) | left (int32) |
+--------------+--------------+
| next (int64) |
+-----------------------------+
| previous (int64) |
+-----------------------------+
left is the offset to the beginning of a previous chunk.
Free chunks have MSB of the size unset.
Free chunks are linked by double-linked lists (using next and previous) starting from the
corresponding bin.
Occupied chunk format (8 byte header + payload):
+--------------+--------------+
| size (int32) | left (int32) |
+--------------+--------------+
| user data |
+-----------------------------+
Occupied chunks have MSB of the size set.
Invariants:
Bins contain chunks with sizes from the bin size inclusive up to the next bin size exclusive
(see chooseBin(int)).
OutOfMemoryException| Constructor and Description |
|---|
Malloc(long capacity) |
Malloc(long base,
long capacity) |
Malloc(MappedFile mmap) |
| Modifier and Type | Method and Description |
|---|---|
int |
allocatedSize(long address) |
long |
base() |
long |
calloc(int size) |
void |
free(long address) |
long |
getFreeMemory() |
long |
getTotalMemory() |
long |
getUsedMemory() |
long |
malloc(int size) |
void |
verify()
Verify the layout of the heap.
|
public Malloc(long capacity)
public Malloc(long base,
long capacity)
public Malloc(MappedFile mmap)
public final long base()
public long getTotalMemory()
getTotalMemory in interface MallocMXBeanpublic long getFreeMemory()
getFreeMemory in interface MallocMXBeanpublic long getUsedMemory()
getUsedMemory in interface MallocMXBeanpublic int allocatedSize(long address)
Copyright © 2019. All rights reserved.