|
template<typename TYPE , std::size_t SIZE> |
std::size_t | numof (const TYPE(&)[SIZE]) |
| Retrieve the size of an array.
|
|
template<class T > |
constexpr auto | wrap_at (const T &c, std::size_t i) -> const typename T::value_type & |
| Returns a wrapped reference to an element at index i in container c .
|
|
template<class T > |
constexpr auto | clamp_to_edge (const T &c, std::size_t i) -> const typename T::value_type & |
| Returns a clamped reference to an element at index i in container c .
|
|
template<typename T , std::size_t N> |
constexpr const T & | random_at (const T(&array)[N]) |
|
template<typename T > |
constexpr const T::value_type & | random_at (const T &container, const typename T::value_type &default_value=typename T::value_type{}) |
|
std::string | fs (const char *format,...) |
| Format a string with variable arguments.
|
|
void * | mallocz (size_t bytesize_) |
| Allocate and zero-initialize a block of memory.
|
|
void | print_mallinfo () |
| Print memory allocation information.
|
|
Utility functions for memory management and string operations.
This module provides a collection of helper functions for memory management and string operations in C++ programs. The functions include:
print_mallinfo
: Displays current dynamic memory allocation statistics.
mallocz
: Allocates a block of memory and initializes it to zero.
fs
: Formats a string with variable arguments similar to printf
.
memsetz
: Zero-initializes a block of memory.
numof
: Returns the number of elements in a static array.
These functions are intended to simplify common tasks and improve code readability and maintainability.
Note: This module is not thread-safe and is intended for use in single-threaded environments or where thread-safety is managed externally.
Example usage:
#include <iostream>
int main() {
size_t size = 100;
if (ptr != nullptr) {
std::cout << "Memory allocated and zero-initialized." << std::endl;
free(ptr);
}
std::string formatted =
fs(
"Hello, %s! You have %d new messages.",
"Alice", 5);
std::cout << formatted << std::endl;
int arr[10];
size_t arr_size =
numof(arr);
std::cout << "Array size: " << arr_size << std::endl;
return 0;
}
Utility functions for memory management and string operations.
void * mallocz(size_t bytesize_)
Allocate and zero-initialize a block of memory.
Definition sublibc.cpp:25
std::size_t numof(const TYPE(&)[SIZE])
Retrieve the size of an array.
Definition sublibc.h:77
void print_mallinfo()
Print memory allocation information.
Definition sublibc.cpp:10
std::string fs(const char *format,...)
Format a string with variable arguments.
Definition sublibc.cpp:32
The functions provided by this module are not mandatory for use but are designed to aid in the development and debugging of applications by offering convenient utilities.
- Note
- This module is intended for debugging purposes and its use is optional.