Hi ,
I have created a program using CMapStrintToPtr where I would be
mapping
structure ptr to map string. This is just a sample program which I
thought
to avoid linear search in link list since my actual data is so huge.
I created a Windows console program. Since I am assigning a memory
block to
the structure node and I am not freeing it anyway in the program. Will
there be memory leak. Is it necessary to free the memory in my code.
If I want to free
how should I free it. I am thinking of get cmP.GetCount then get 1st
strcuture ptr by cmP.GetStartPos ition then go through each by
cmP.GetNextAsso c and free
each structure ptr we get. Is this correct. Please tell more.
My code is
#include <iostream.h>
#include <afxcoll.h>
#include <conio.h>
CMapStringToPtr cmP;
struct vj
{
int type;
char name_type[100];
};
void mapFunction(cha r *mapStr, int typ, char *typeName)
{
struct vj *vijay;
vijay = (struct vj *) malloc (sizeof (struct vj));
strcpy(vijay->name_type, typeName);
vijay->type = typ;
cmP.SetAt ( mapStr, vijay);
}
void main()
{
mapFunction("li ", 3, "line");
mapFunction("ls ", 4, "linestring ");
mapFunction("sh ", 5, "shape");
struct vj *temp;
cmP.Lookup ("sh", (void*&)temp);
cout<< temp->type <<" " << temp->name_type << endl;
getch();
}
Thanks vijay.