c++ - Aligned member variables and dynamic allocation -
So basically, it's so close to me that I have a I have another class which is not itself a coalition, but there is a I need to allocate examples of dynamically How can I guarantee that the I can use (and generally prefer) the features of C ++ 11, probably what is You can use the placements new to create memory allocation from the object creation To reduce: A and C ++ IH route must use std :: vector with an allocation allocation. mat4 class Is composed of
__M 128 and it needs to be aligned to the 16-byte limit:
_MM_ALIGN16 square mat4 {...};
mat4 in it.
class other class {private: mat4 matrix; // Other data whose alignment really does not matter ...};
another class , ala:
other class = stuff = new other Class [n];
mat4 inside the example (s) will be aligned properly, while still
mat4 the creator ?
aligned_storage what I see? How do I use it in this case?
/ * memory allocation * / #ifdef _MSC_VER zero * buffer = _aligned_malloc (n * sizeof (other class), 16); # Elsie Zero * buffer = memline (16, n * size (other class)); #endif / * item creation * / other class * array = new (buffer) other class [n]; / * Use your objects * / ... / * for object destruct * / (size_t i = 0; i & lt; n; i ++) {array [i] ~ OtherClass (); } / * Memory Delocution * / #ifdef _MSC_VER _aligned_free (buffer); Buffer = nalper; #else free (buffer); Buffer = nalper; #endif
Comments
Post a Comment