I'm trying to change a dynamic memory object to static memory use to hopefully free up memory in a way.
Original code(dynamic):
Class.h:
Class() {
auto output = std::unique_ptr<uint8_t[]>(new uint8_t[size]);
Call(output.get());
memcpy(randomlocation, output.get(), size);
}
Call(Byte *dest) {
doStuff..
}
I'm very confused how I can do a similar .get() but with a non unique-ptr. I've seen &* may work but haven't had any luck.
My trial of static:
Class.h:
uint8_t *output[64];
Class() {
Call(reinterpret_cast<Byte*>(&*output));
}
I have tried other ways like no &* and different ways of casts and haven't had any luck. It compiles sometimes, but doesn't seem to work right. Wanting to see if this part is wrong, if not then I will at least know I'm doing this part right.
uint8_t *output[64];notByte output[64];or betterstd::array<Byte, 64> output;? Note global state usually means fragile code.uint8_t *output[64];-- This declares an array of 64 pointers. Is this your intention?memcpyis kind of a legacy "C" thing, in C++ it is best replaced withstd::copy