I need to create an array of Structures. I'm trying to do it this way and it compiles fine.
Is my use of delete all right? Will it ensure that the memory is freed?
Because if I don't free the memory properly I'll most likely run into a segmentation fault at runtime.
struct scheq
{
uint64_t type;
uint64_t destreg;
uint64_t desttag;
bool src1r;
bool src2r;
uint64_t src1t;
uint64_t src2t;
};
scheq* S0; //global variable I need to use it in all the functions
void setup_proc(uint64_t r, uint64_t k0, uint64_t k1, uint64_t k2, uint64_t f, uint64_t m) {
S0=new scheq[m*k0]; //I get m and k0 so now I know the size of the scheq array
}
void complete_proc(proc_stats_t *p_stats) {
delete []S0; //I delete S0 thus freeing the memory allocated to it.
}
I am using the terminal in a Virtual Linux Machine.
Thanks. Any help is greatly appreciated. :)
I agree. It looks fine, as long as you're sure that everything gets called and never more than twice and a row and setup_proc gets called first.
If I don't free the memory properly I'll most likely run into a segmentation fault at runtime.
Well, thankfully you don't have to worry about that nasty little issue if you don't free your memory. You'll instead run into a memory leak, in which a program keeps drawing memory and forgetting to give it back, thus "leaking" it and making it unavailable for other programs to use. Just so you know. :)