I want to dynamically allocate known size of memory (just memory, not bothering about type) and fill it with exactly the same amount of data but any type (I'm only sure it will be primitive type). Ofc later I'm going to free it.
Is it ok? :
auto dest = new int8_t[n];
std::memcpy(dest, src, n);
delete[] dest;
src
is ptr to an array of size n
(Bytes).
I've ofc chosen int8_t
becuase it's the clearest way to allocate certain amount of memory.
In fact the code above isn't exaclt what it will be. delete[]
will be called on pointer of type which actually it points to.
So for example if src was an array of floats (forget about last line of above code):
float * ptr = dest;
delete[] ptr;
So again. Will it be ok?