Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
updated README and vmem documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
septag committed May 1, 2020
1 parent be9c204 commit fdfc085
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ This library currently contains these functionalities (listed by header files):
- Semaphore
- Signal
- [timer.h](include/sx/timer.h): Portable high-res timer, wrapper over [sokol_time](https://github.com/floooh/sokol)
- [virtual-alloc.h](include/sx/virtual-alloc.h): Portable virtual memory allocator and low-level portable virtual memory management functions
- [vmem.h](include/sx/vmem.h): Page based virtual memory allocator
- [math.h](include/sx/math.h):
- Standard floating-point
- Vector (2,3,4)
Expand All @@ -61,14 +61,18 @@ This library currently contains these functionalities (listed by header files):
- Basic file operations
- Path manipulation functions (c-string)
- [bheap.h](include/sx/bheap.h): Binary heap implementation
- [tlsf-alloc.h](include/sx/tlsf-alloc.h): Tlsf (Two-Level Segregated Fit memory) memory allocator. Wrapper over [Mathew Conte's implementation](http://tlsf.baisoku.org)
- [simd.h](include/sx/simd.h): portable 128bit simd math intrinsics. currently there are two implementations: reference and SSE. ARM Neon will be added soon.
- [ringbuffer.h](include/sx/ringbuffer.h): Basic ring-buffer (circular buffer)
- [lockless.h](include/sx/lockless.h): lockless data structures.
- Self-contained single-producer-single-consumer queue
- [linear-buffer.h](include/sx/linear-buffer.h): Helper custom memory allocator useful for allocating structures with arrays of data in a single allocation call
- [bitarray.h](include/sx/bitarray.h): utility data structure to hold arbitary number of bits

## Changes
### v1.0.0 (May 2020)
- [BREAKING]: Removed `virtual-alloc.h` and replaced it with the new `vmem.h`. virtual-alloc was not Suitable for general memory allocator. So I ditched it completely and replaced with a cleaner, better virtual memory allocation scheme. which is page based
- [BREAKING]: Removed `tlsf-alloc` and all of it's dependencies. In order to cut the maintainable code and reduce repo size. I decided to remove this and leave it for the user to use the open-source [tlsf allocator](https://github.com/mattconte/tlsf).

## Build
### Current supported platforms

Expand Down
46 changes: 24 additions & 22 deletions include/sx/vmem.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
//
// Copyright 2018 Sepehr Taghdisian (septag@github). All rights reserved.
// Copyright 2020 Sepehr Taghdisian (septag@github). All rights reserved.
// License: https://github.com/septag/sx#license-bsd-2-clause
//
// virtual-alloc.h - v1.0 - Virtual memory allocator
// vmem.h - v1.0 - Virtual memory page allocator
//
// Uses OS specific virtual memory functions
//
// virtualalloc: standard sequential virtual memory allocator
// Virtual memory can be reserved in large sizes and commited later on demand
// Very useful for large buffer allocations, instead of allocating directly from heap
// Memory is only allocate sequentially and will not be reused
// so the limitation is not to hit the 'reserve_sz' max
//
// sx_virtualalloc_init Initialize and reserves virtual memory for the allocator
// Reserved size will not be commited until it's alloacated and
// touched 'reserved_sz' value will grow to OS-specific aligned
// page size
//
// sx_virtualalloc_release Releases memory commited and reserved by virtual-allocator
//
// NOTE: When you use the sx_alloc object for allocating, the memory will be commited and you will
// get a valid pointer. But still the memory is not allocated from heap until you touch the
// contents of the memory block.
// Also the allocation sizes will grow to OS-specific aligned page size (for example 4k),
// .. so try to allocate in larger chunks from this type of allocator
//
// the vmem set of functions can be used to reserve and commit protected pages of virtual memory
// from the system. It works by reserving maximum number of pages. So the pointer range will be
// reserved, but not actually mapped to physical memory.
// After init, you can use commit_page/commit_pages functions to start using specific pages.
// Pages are defined by their index. So, if you have for example, 4096 maximum pages. You can commit
// and free pages from 0..4095, and you should keep track of free/allocated pages in your program.
// Page memory size is OS/System dependent. You can actually get it's size with `sx_os_pagesz`
//
// Functions:
// sx_vmem_get_bytes(num_pages) returns number of bytes allocated for N pages
// sx_vmem_get_needed_pages(bytes) returns number of needed pages to N bytes
// you can pass the return value to sx_vmem_init function
// sx_vmem_init initialize the vmem context and reserve `max_pages`
// sx_vmem_release Releases the vmem context and frees all memory
// sx_vmem_commit_page/pages Commits `num_pages` that you need to actually allocate
// and use. Returns the pointer to the start of pages
// start_page_id: Zero based index of the page you want
// num_pages: Number of pages starting from `start_page_id`
// sx_vmem_free_page/pages Free a single or a range of pages to be used later again
// Parameters are same as commit functions
// sx_vmem_commit_size Returns total commited bytes.
// Basically num_pages*page_size
#pragma once

#include "sx.h"
Expand Down
21 changes: 21 additions & 0 deletions sx.sublime-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"folders": [
{
"path": ".",
"folder_exclude_patterns": [
"build",
".vscode",
".clangd",
"bin",
"build-*"
],
"file_exclude_patterns": [
".gitignore",
".travis.yml",
".gitmodules",
".clang-format",
"compile_commands.json"
]
}
]
}

0 comments on commit fdfc085

Please sign in to comment.