Hello all!
I am programming a genetic algorithm.
Normally, i use only two populations at each iteration, (the same objects).
The memory usage grows with the number of iterations, although I'm only using the same objects.
if I consider like 10000 iterations, no problem occurs (only i didn't get near the optimum). Above that, i get this unhandled exception:
exception: std::bad_alloc at memory location dbgheap.c
I am suspecting two functions in my code (I can't copy/paste all of it) to be the cause of the error. but i really don't know what's the deal!
can you please help me!
I am posting the functions in replies because of the length limit.
structs used:
-------------
struct FD_C
{
int FD_index;
int C; //card type
~FD_C(){};
};
struct Period
{
bool vacancy; // true: vacant, false: busy
int nb_FD;
vector <FD_C> fd_c;
~Period(){};
};
struct WFD //Usage of wavelengths over SPs. contains Fragment demands (FD) using a certain lambda
{
int lambda;
int nb_FD;
vector <FD_C> FD_table; // indices of FDs
Period *Emploi_du_temps;
~WFD(){};
};
struct SP_monitor // contains FDs carried by used lambdas over a certain SP
{
int SP;
int nb_lambda; // how many lambdas are used over a certain SP
vector <WFD> WFD_monitor;
~SP_monitor(){
};
};
struct Monitor //contains all used SPs, with their usage (which FD is using which SP)
{
int nb_SP;
vector<SP_monitor> sp_monitor;
~Monitor(){};
};
struct period_monitor
{
public:
int **tx;// contains 1 if it's used to transmit a signal, -1 if its corresponding receiver is receiving and it's not transmitting at the same time, 0 otherwise1
int **rx;
period_monitor()
{
tx=new int*[C];
rx=new int*[C];
for(int i=0;i<C;i++)
{
tx[i]=new int[W];
rx[i]=new int[W];
}
};
~period_monitor()
{
for(int i=0;i<C;i++)
{
delete []tx[i];
delete []rx[i];
yes, that's what i don't get. functions normally kill their inside variables before being through.
and in my main code, iterations use the same objects. Same two objects!
why is it that memory usage is greater with each iteration! I'm helpless!
yes indeed i forgot delete[] rx;
as for the letters, they are const global variables.
I am trying to see if pushing variables of type WFD into a vector is doing this huge use of memory, because of the pointer. I suspect it's not being freed at the end of execution
struct WFD //Usage of wavelengths over SPs. contains Fragment demands (FD) using a certain lambda
{
int lambda;
int nb_FD;
vector <FD_C> FD_table; // indices of FDs
Period *Emploi_du_temps;
~WFD(){};