STL List Container memory problem
From: Lee Garrington (zen25492_at_zen.co.uk)
Date: 01/31/04
- Next message: Materialised: "Efficient Text File Copy"
- Previous message: RPS: "HELP -- API function won't compile"
- Next in thread: Leor Zolman: "Re: STL List Container memory problem"
- Reply: Leor Zolman: "Re: STL List Container memory problem"
- Reply: Jerry Coffin: "Re: STL List Container memory problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 31 Jan 2004 00:20:36 -0000
Hey,
I am having a problem that I cannot explain although more than likely there
is something wrong with my code. I have a board and a list, which holds all
the squares in the board which could potentially have available moves.
The algorithm goes through all these squares using an iterator and if it
passes a square that has no possible moves ever then it erases it.
Otherwise it checks if the square currently has moves available and if it
does then it erases this square from the list and makes the move which may
result in additional elements being appended to the list.
If the square could potentially have moves but doesnt have any available at
the moment the iterator simply moves onto the next square.
I use win XP and looking at the task manager the board I tested on uses 98Mb
of memory. When I activate the algorithm this shoots up to 155Mb and I have
no reason why because I determined that the maximum size of the list is
approximately 2500000 elements which equates to approx:-
2500000 * (8bytes(overhead of list per element) + 4bytes(actual element))
This = 28Mb not the figure almost double that.
I figured there might be a memory leak, so here is some code.
std::list<Point> s;
struct Point
{
short x;
short y;
};
void AddPoint(int x, int y)
{
Point p;
p.x = x;
p.y = y;
s.push_back(p);
}
void AddPoint(Point p)
{
s.push_back(p);
}
bool MakeMoves(Board *board)
{
std::list<Point>::iterator i;
do
{
i = s.begin();
do
{
Point p = *i;
if (board square p will never have any moves)
i = s.erase(i);
else
{
if (board square has available moves)
{
make the moves (may include calls to AddPoint());
i = s.erase(i);
}
else ++i;
}while (i != s.end());
}while (moves were made within the inner loop)
s.clear();
return true;
}
It works fine, no exceptions etc but I just cant understand the memory it
uses. Is there something wrong with the code?
Thanx in advance
Lee
- Next message: Materialised: "Efficient Text File Copy"
- Previous message: RPS: "HELP -- API function won't compile"
- Next in thread: Leor Zolman: "Re: STL List Container memory problem"
- Reply: Leor Zolman: "Re: STL List Container memory problem"
- Reply: Jerry Coffin: "Re: STL List Container memory problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|