mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-30 00:08:03 +00:00
Update Vector code
This commit is contained in:
parent
754e4ea0c7
commit
a142c54a7c
@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#ifndef __FENNIX_KERNEL_VECTOR_H__
|
||||||
|
#define __FENNIX_KERNEL_VECTOR_H__
|
||||||
|
|
||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -40,6 +43,7 @@ public:
|
|||||||
#ifdef DEBUG_MEM_ALLOCATION
|
#ifdef DEBUG_MEM_ALLOCATION
|
||||||
debug("VECTOR INIT: Vector( %lld %llx )", Size, Initial);
|
debug("VECTOR INIT: Vector( %lld %llx )", Size, Initial);
|
||||||
#endif
|
#endif
|
||||||
|
assert(Size > 0);
|
||||||
VectorBuffer = new T[Size];
|
VectorBuffer = new T[Size];
|
||||||
for (size_t i = 0; i < Size; i++)
|
for (size_t i = 0; i < Size; i++)
|
||||||
VectorBuffer[i] = Initial;
|
VectorBuffer[i] = Initial;
|
||||||
@ -52,6 +56,7 @@ public:
|
|||||||
#ifdef DEBUG_MEM_ALLOCATION
|
#ifdef DEBUG_MEM_ALLOCATION
|
||||||
debug("VECTOR INIT: Vector( <vector> )->Size: %lld", VectorSize);
|
debug("VECTOR INIT: Vector( <vector> )->Size: %lld", VectorSize);
|
||||||
#endif
|
#endif
|
||||||
|
assert(VectorSize > 0);
|
||||||
VectorBuffer = new T[VectorSize];
|
VectorBuffer = new T[VectorSize];
|
||||||
for (size_t i = 0; i < VectorSize; i++)
|
for (size_t i = 0; i < VectorSize; i++)
|
||||||
VectorBuffer[i] = Vector.VectorBuffer[i];
|
VectorBuffer[i] = Vector.VectorBuffer[i];
|
||||||
@ -62,7 +67,11 @@ public:
|
|||||||
#ifdef DEBUG_MEM_ALLOCATION
|
#ifdef DEBUG_MEM_ALLOCATION
|
||||||
debug("VECTOR INIT: ~Vector( ~%lx )", VectorBuffer);
|
debug("VECTOR INIT: ~Vector( ~%lx )", VectorBuffer);
|
||||||
#endif
|
#endif
|
||||||
delete[] VectorBuffer;
|
if (VectorBuffer != nullptr)
|
||||||
|
{
|
||||||
|
delete[] VectorBuffer;
|
||||||
|
VectorBuffer = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__no_instrument_function void remove(size_t Position)
|
__no_instrument_function void remove(size_t Position)
|
||||||
@ -160,8 +169,14 @@ public:
|
|||||||
{
|
{
|
||||||
VectorCapacity = 0;
|
VectorCapacity = 0;
|
||||||
VectorSize = 0;
|
VectorSize = 0;
|
||||||
VectorBuffer = 0;
|
if (VectorBuffer != nullptr)
|
||||||
|
{
|
||||||
|
delete[] VectorBuffer;
|
||||||
|
VectorBuffer = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__no_instrument_function T *data() { return VectorBuffer; }
|
__no_instrument_function T *data() { return VectorBuffer; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // !__FENNIX_KERNEL_VECTOR_H__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user