mirror of
https://github.com/godotengine/godot.git
synced 2024-11-15 00:23:27 +00:00
better array alignment
This commit is contained in:
parent
0846ab6a5f
commit
3ac0267daa
@ -308,11 +308,11 @@ T* memnew_arr_template(size_t p_elements,const char *p_descr="") {
|
|||||||
same strategy used by std::vector, and the DVector class, so it should be safe.*/
|
same strategy used by std::vector, and the DVector class, so it should be safe.*/
|
||||||
|
|
||||||
size_t len = sizeof(T) * p_elements;
|
size_t len = sizeof(T) * p_elements;
|
||||||
unsigned int *mem = (unsigned int*)Memory::alloc_static( len + sizeof(size_t), p_descr );
|
unsigned int *mem = (unsigned int*)Memory::alloc_static( len + MAX(sizeof(size_t), DEFAULT_ALIGNMENT), p_descr );
|
||||||
T *failptr=0; //get rid of a warning
|
T *failptr=0; //get rid of a warning
|
||||||
ERR_FAIL_COND_V( !mem, failptr );
|
ERR_FAIL_COND_V( !mem, failptr );
|
||||||
*mem=p_elements;
|
*mem=p_elements;
|
||||||
mem = (unsigned int *)( ((uint8_t*)mem) + sizeof(size_t));
|
mem = (unsigned int *)( ((uint8_t*)mem) + MAX(sizeof(size_t), DEFAULT_ALIGNMENT));
|
||||||
T* elems = (T*)mem;
|
T* elems = (T*)mem;
|
||||||
|
|
||||||
/* call operator new */
|
/* call operator new */
|
||||||
@ -331,14 +331,14 @@ T* memnew_arr_template(size_t p_elements,const char *p_descr="") {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
size_t memarr_len(const T *p_class) {
|
size_t memarr_len(const T *p_class) {
|
||||||
|
|
||||||
uint8_t* ptr = ((uint8_t*)p_class) - sizeof(size_t);
|
uint8_t* ptr = ((uint8_t*)p_class) - MAX(sizeof(size_t), DEFAULT_ALIGNMENT);
|
||||||
return *(size_t*)ptr;
|
return *(size_t*)ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void memdelete_arr(T *p_class) {
|
void memdelete_arr(T *p_class) {
|
||||||
|
|
||||||
unsigned int * elems = (unsigned int*)(((uint8_t*)p_class) - sizeof(size_t));
|
unsigned int * elems = (unsigned int*)(((uint8_t*)p_class) - MAX(sizeof(size_t), DEFAULT_ALIGNMENT));
|
||||||
|
|
||||||
for (unsigned int i=0;i<*elems;i++) {
|
for (unsigned int i=0;i<*elems;i++) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user