Reputation: 7
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.
Upvotes: 0
Views: 175
Reputation: 13
Use uint8_t output[64];
instead. The output is like uint8_t*
to 64 bytes of static memory.
This works:
void cal(uint8_t* dest)
{
...
}
uint8_t output[64];
cal(output);
Upvotes: 1