feature (kernel): Implemented 'bitmap_init'

This commit is contained in:
antifallobst 2023-02-12 19:56:30 +01:00
parent 630c2e9762
commit ecf881967d
2 changed files with 8 additions and 4 deletions

View File

@ -499,10 +499,10 @@ The size is the size of the buffer in bytes, to get the amount of storable bits
#### `bitmap_init_from_buffer(buffer, size)` - function (bitmap_T) #### `bitmap_init_from_buffer(buffer, size)` - function (bitmap_T)
Creates a bitmap object from a given buffer and size Creates a bitmap object from a given buffer and size
#### `bitmap_init(size)` - function (bitmap_T) [NOT IMPLEMENTED YET] #### `bitmap_init(size)` - function (bitmap_T)
Allocates memory to hold a bitmap in the given size and returns a `bitmap_T` with that buffer and size. Allocates memory to hold a bitmap in the given size and returns a `bitmap_T` with that buffer and size.
#### `bitmap_destruct(bitmap*)` - function (void) [NOT IMPLEMENTED YET] #### `bitmap_destruct(bitmap*)` - function (void)
Frees the memory of the given bitmap created with `bitmap_init`. Frees the memory of the given bitmap created with `bitmap_init`.
#### `bitmap_set(bitmap*, index, value)` - function (bool) #### `bitmap_set(bitmap*, index, value)` - function (bool)

View File

@ -14,6 +14,7 @@
*/ */
#include "utils/bitmap.h" #include "utils/bitmap.h"
#include "utils/memory.h"
bitmap_T bitmap_init_from_buffer(void* buffer, uint32_t size) { bitmap_T bitmap_init_from_buffer(void* buffer, uint32_t size) {
bitmap_T bitmap; bitmap_T bitmap;
@ -23,11 +24,14 @@ bitmap_T bitmap_init_from_buffer(void* buffer, uint32_t size) {
} }
bitmap_T bitmap_init(uint32_t size) { bitmap_T bitmap_init(uint32_t size) {
// TODO: implement bitmap malloc constructor bitmap_T bitmap;
bitmap.size = size / 8 + 1;
bitmap.buffer = memory_allocate(bitmap.size);
return bitmap;
} }
void bitmap_destruct(bitmap_T* bitmap) { void bitmap_destruct(bitmap_T* bitmap) {
memory_free(bitmap->buffer);
} }
bool bitmap_set(bitmap_T* bitmap, uint32_t index, bool value) { bool bitmap_set(bitmap_T* bitmap, uint32_t index, bool value) {