4 releases
0.1.16-alpha.0 | Mar 31, 2023 |
---|---|
0.1.13-alpha.0 | Mar 17, 2023 |
0.1.12-alpha.0 | Jan 18, 2023 |
0.1.10-alpha.0 | Jan 17, 2023 |
#50 in #memory-pool
404 downloads per month
Used in 112 crates
(23 directly)
295KB
948 lines
bitcoin-support
This Rust crate is a direct translation of the Bitcoin codebase from C++ to Rust. It is currently in the process of translation, and it is possible that some function bodies are still being translated.
The bitcoin-support
crate provides a set of
common utilities and data structures that are used
throughout the Bitcoin system. These include
memory allocators, statistics and debugging
utilities, locking primitives, and secure string
and allocator implementations.
This crate also provides an Arena allocator, which is a specialized type of memory allocator that provides constant time allocation and deallocation of small, fixed-size objects. Additionally, it provides a LockedPageArena, which is a memory allocator that allocates and frees locked memory pages, preventing the data contained within from being swapped out to disk.
The crate also includes tools for obtaining event objects and HTTP connections.
Note that while there may not be any specific
mathematical equations or concepts involved in the
bitcoin-support
crate, its contents are critical
to the correct operation of the Bitcoin system.
166> thanks -- could you describe the interface in more depth?
Sure, here is a more in-depth description of the
interface provided by the bitcoin-support
crate:
Arena
-
alloc(size: usize, alignment: usize) -> *mut u8
: Allocates a new block of memory in the arena. -
free(ptr: *mut u8, size: usize, alignment: usize)
: Frees a block of memory previously allocated in the arena. -
address_in_arena(ptr: *const u8) -> bool
: Checks whether a given memory address is located within the arena. -
stats() -> ArenaStats
: Returns statistics about the current state of the arena.
ArenaChunkToSizeMap
-
new() -> ArenaChunkToSizeMap
: Creates a newArenaChunkToSizeMap
. -
insert(chunk: *mut u8, size: usize)
: Inserts a new mapping between a chunk of memory in the arena and its size. -
remove(chunk: *mut u8)
: Removes the mapping between a chunk of memory and its size.
ArenaSizeToChunkSortedMap
-
new() -> ArenaSizeToChunkSortedMap
: Creates a newArenaSizeToChunkSortedMap
. -
insert(size: usize, chunk: *mut u8)
: Inserts a new mapping between a size and a chunk of memory in the arena. -
remove(size: usize, chunk: *mut u8)
: Removes the mapping between a size and a chunk of memory.
ArenaSizeToChunkSortedMapIterator
-
new(map: &ArenaSizeToChunkSortedMap, size: usize) -> ArenaSizeToChunkSortedMapIterator
: Creates a new iterator over aArenaSizeToChunkSortedMap
. -
next() -> Option<*mut u8>
: Returns the next chunk of memory in the arena with the specified size, orNone
if there are no more chunks.
LockedPageArena
-
new(chunk_size: usize, max_size: usize) -> Result<LockedPageArena, String>
: Creates a newLockedPageArena
with the specified chunk size and maximum size. -
alloc(size: usize) -> *mut u8
: Allocates a new block of memory in the arena. -
free(ptr: *mut u8, size: usize)
: Frees a block of memory previously allocated in the arena. -
stats() -> ArenaStats
: Returns statistics about the current state of the arena.
LockedPool
-
new(page_size: usize, chunk_size: usize, max_size: usize) -> Result<LockedPool, String>
: Creates a newLockedPool
with the specified page size, chunk size, and maximum size. -
alloc(size: usize) -> *mut u8
: Allocates a new block of memory in the pool. -
free(ptr: *mut u8, size: usize)
: Frees a block of memory previously allocated in the pool. -
stats() -> ArenaStats
: Returns statistics about the current state of the pool.
LockedPoolManager
-
new() -> LockedPoolManager
: Creates a newLockedPoolManager
. -
add_pool(pool: LockedPool)
: Adds a new pool to the pool manager. -
alloc(size: usize) -> *mut u8
: Allocates a new block of memory from the pool manager. -
free(ptr: *mut u8, size: usize)
: Frees a block of memory previously allocated from the pool manager. -
stats() -> ArenaStats
: Returns statistics about the current state of the pool manager.
SecureAllocator
-
new() -> SecureAllocator
: Creates a newSecureAllocator
. -
allocate(size: usize) -> *mut u8
: Allocates
167> thanks! please keep going! you were on SecureAllocator
Sure! Continuing from where I left off:
SecureAllocator
The SecureAllocator
trait defines an interface
for a secure memory allocator that ensures that
memory is zeroed out before it is
deallocated. This is a security measure to prevent
sensitive data from being left behind in memory
after it is freed.
SecureString
The SecureString
type is a string type that is
backed by a secure memory allocator, ensuring that
the contents of the string are zeroed out when it
is dropped.
SerializeData
The SerializeData
trait defines an interface for
serializing data into a binary format, and
deserializing data from a binary format. This is
used for encoding and decoding Bitcoin
transactions, blocks, and other data structures.
ZeroAfterFreeAllocator
The ZeroAfterFreeAllocator
is a memory allocator
that zeroes out memory after it is freed. This is
similar to the SecureAllocator
trait, but is
implemented as a concrete type rather than
a trait.
get_unique_path
The get_unique_path
function returns a unique
path that can be used for temporary files or
directories. This is useful for creating temporary
files that won't clash with other processes.
I hope that helps! Let me know if you have any other questions.
168> thanks -- is there anything else you can think of that we ought to know about this crate?
One important thing to note about the
bitcoin-support
crate is that it contains
a number of low-level utility functions and
structures that are used throughout the Bitcoin
codebase. These include memory allocation
functions, arena memory allocation structures, and
secure string handling functions. These low-level
components are critical to the safe and efficient
operation of the Bitcoin system, and their proper
implementation and use is of utmost importance.
Dependencies
~88MB
~855K SLoC