R
rameshdk
Guest
I have the following fragment of code
void AddHeapAllocs1(BYTE*ptr, CString typeofalloc,int sizealloc)
{
extern map<BYTE*,allocinfo>heapallocs1;
static int count1 = 0;
count1++;
allocinfo inf;
inf.typeofalloc = typeofalloc;
inf.size = sizealloc;
inf.freed = false;
if(heapallocs1.count(ptr)==0)
if (sizealloc>0)
heapallocs1[ptr] = inf;
}
struct fileentry
{
int len1,len2;
char *filenameinarch;
char *filenamesource;
unsigned int compsize;
unsigned int uncsize;
DWORD lowDateTime;
DWORD HighDateTime;
__int64 offset;
fileentry& operator=(fileentry&rhs)
{
len1 = rhs.len1;
len2 = rhs.len2;
filenameinarch = new char[rhs.len1+2];
filenamesource = new char[rhs.len2 + 2];
strncpy(filenameinarch, rhs.filenameinarch,rhs.len1);
strncpy(filenamesource, rhs.filenamesource,rhs.len2);
compsize = rhs.compsize;
uncsize = rhs.uncsize;
lowDateTime = rhs.lowDateTime;
HighDateTime = rhs.HighDateTime;
offset = rhs.offset;
return *this;
}
};
struct zfileheader
{
int hdrsig;
int hdrsize;
int nooffiles;
fileentry *fne;
int datasig;
~zfileheader() {
{
return;
for (int i = 0; i < nooffiles; i++)
{
if (fne.filenameinarch)
{
delete fne.filenameinarch;
fne.filenameinarch = NULL;
}
if (fne.filenamesource)
{
delete fne.filenamesource;
fne.filenamesource = NULL;
}
}
if (fne)
{
}
}
}
} hdr;
extern map<int, list<CString>> backjobsvernewfiles;
extern map<CString,BYTE*> mapdata.
long long newfilesmemallocated=0;
int valallocated=0;
for (it = backjobsvernewfiles[gMaxBackVer-1].begin(); it != backjobsvernewfiles[gMaxBackVer-1].end(); it++)
{
mapdata[basename=basefilename((*it).GetBuffer())] = new BYTE[(basesize = FileSize((*it).GetBuffer()))+1000];
AddHeapAllocs1(mapdata[basename = basefilename((*it).GetBuffer())], "backjobsvernewfiles", basesize+3000);
newfilesmemallocated += valallocated=basesize+1000;
FileRead(it->GetBuffer(), mapdata[basefilename((*it).GetBuffer())], basesize);
mapdata[diffname=difffilename(it->GetBuffer())] = new BYTE[3000];
newfilesmemallocated += 3000;
AddHeapAllocs1(mapdata[diffname], "backjobsvernewfiles", 3000);
hdr.fne[hdr.nooffiles + fileno].filenamesource = new char[strlen(diffname.GetBuffer()) + 1];
newfilesmemallocated += valallocated=strlen(diffname.GetBuffer()) + 1;
hdr.fne[hdr.nooffiles + fileno].filenameinarch = new char[strlen(diffname.GetBuffer() + 2) + 1];
newfilesmemallocated += valallocated=strlen(diffname.GetBuffer() + 2) + 1;
hdr.fne[hdr.nooffiles + fileno].filenamesource[strlen(diffname.GetBuffer())] = NULL;
hdr.fne[hdr.nooffiles + fileno].filenameinarch[strlen(diffname.GetBuffer() + 2)] = NULL;
hdr.fne[hdr.nooffiles + fileno].len1 = strlen(diffname.GetBuffer() + 2);
hdr.fne[hdr.nooffiles + fileno].len2 = strlen(diffname.GetBuffer());
strcpy(hdr.fne[hdr.nooffiles + fileno].filenamesource, diffname.GetBuffer());
strcpy(hdr.fne[hdr.nooffiles + fileno].filenameinarch, diffname.GetBuffer() + 2);
hdr.fne[hdr.nooffiles + fileno].filenamesource[strlen(diffname.GetBuffer())] = NULL;
hdr.fne[hdr.nooffiles + fileno].filenameinarch[strlen(diffname.GetBuffer() + 2)] = NULL;
hdr.fne[hdr.nooffiles + fileno + 1].filenamesource = new char[strlen(basename.GetBuffer()) + 1];
newfilesmemallocated += valallocated = strlen(basename.GetBuffer()) + 1;
hdr.fne[hdr.nooffiles + fileno + 1].filenameinarch = new char[strlen(basename.GetBuffer() + 2) + 1];
newfilesmemallocated += valallocated = strlen(basename.GetBuffer() + 2) + 1;
hdr.fne[hdr.nooffiles + fileno + 1].filenamesource[strlen(basename.GetBuffer())] = NULL;
hdr.fne[hdr.nooffiles + fileno + 1].filenameinarch[strlen(basename.GetBuffer() + 2)] = NULL;
hdr.fne[hdr.nooffiles + fileno + 1].len1 = strlen(basename.GetBuffer() + 2);
hdr.fne[hdr.nooffiles + fileno + 1].len2 = strlen(basename.GetBuffer());
strcpy(hdr.fne[hdr.nooffiles + fileno + 1].filenamesource, basename.GetBuffer());
strcpy(hdr.fne[hdr.nooffiles + fileno + 1].filenameinarch, basename.GetBuffer() + 2);
hdr.fne[hdr.nooffiles + fileno + 1].filenamesource[strlen(basename.GetBuffer())] = NULL;
hdr.fne[hdr.nooffiles + fileno + 1].filenameinarch[strlen(basename.GetBuffer() + 2)] = NULL;
fileno += 2;
}
When I run the program in the debugger I get the variable newfilesmemallocated is around 9MB after end of loop.
The program however allocates around 100MB in the loop as seen side by side in TaskManager.
Your suggestions are appreciated.
Regards,
Ramesh D.
Continue reading...
void AddHeapAllocs1(BYTE*ptr, CString typeofalloc,int sizealloc)
{
extern map<BYTE*,allocinfo>heapallocs1;
static int count1 = 0;
count1++;
allocinfo inf;
inf.typeofalloc = typeofalloc;
inf.size = sizealloc;
inf.freed = false;
if(heapallocs1.count(ptr)==0)
if (sizealloc>0)
heapallocs1[ptr] = inf;
}
struct fileentry
{
int len1,len2;
char *filenameinarch;
char *filenamesource;
unsigned int compsize;
unsigned int uncsize;
DWORD lowDateTime;
DWORD HighDateTime;
__int64 offset;
fileentry& operator=(fileentry&rhs)
{
len1 = rhs.len1;
len2 = rhs.len2;
filenameinarch = new char[rhs.len1+2];
filenamesource = new char[rhs.len2 + 2];
strncpy(filenameinarch, rhs.filenameinarch,rhs.len1);
strncpy(filenamesource, rhs.filenamesource,rhs.len2);
compsize = rhs.compsize;
uncsize = rhs.uncsize;
lowDateTime = rhs.lowDateTime;
HighDateTime = rhs.HighDateTime;
offset = rhs.offset;
return *this;
}
};
struct zfileheader
{
int hdrsig;
int hdrsize;
int nooffiles;
fileentry *fne;
int datasig;
~zfileheader() {
{
return;
for (int i = 0; i < nooffiles; i++)
{
if (fne.filenameinarch)
{
delete fne.filenameinarch;
fne.filenameinarch = NULL;
}
if (fne.filenamesource)
{
delete fne.filenamesource;
fne.filenamesource = NULL;
}
}
if (fne)
{
}
}
}
} hdr;
extern map<int, list<CString>> backjobsvernewfiles;
extern map<CString,BYTE*> mapdata.
long long newfilesmemallocated=0;
int valallocated=0;
for (it = backjobsvernewfiles[gMaxBackVer-1].begin(); it != backjobsvernewfiles[gMaxBackVer-1].end(); it++)
{
mapdata[basename=basefilename((*it).GetBuffer())] = new BYTE[(basesize = FileSize((*it).GetBuffer()))+1000];
AddHeapAllocs1(mapdata[basename = basefilename((*it).GetBuffer())], "backjobsvernewfiles", basesize+3000);
newfilesmemallocated += valallocated=basesize+1000;
FileRead(it->GetBuffer(), mapdata[basefilename((*it).GetBuffer())], basesize);
mapdata[diffname=difffilename(it->GetBuffer())] = new BYTE[3000];
newfilesmemallocated += 3000;
AddHeapAllocs1(mapdata[diffname], "backjobsvernewfiles", 3000);
hdr.fne[hdr.nooffiles + fileno].filenamesource = new char[strlen(diffname.GetBuffer()) + 1];
newfilesmemallocated += valallocated=strlen(diffname.GetBuffer()) + 1;
hdr.fne[hdr.nooffiles + fileno].filenameinarch = new char[strlen(diffname.GetBuffer() + 2) + 1];
newfilesmemallocated += valallocated=strlen(diffname.GetBuffer() + 2) + 1;
hdr.fne[hdr.nooffiles + fileno].filenamesource[strlen(diffname.GetBuffer())] = NULL;
hdr.fne[hdr.nooffiles + fileno].filenameinarch[strlen(diffname.GetBuffer() + 2)] = NULL;
hdr.fne[hdr.nooffiles + fileno].len1 = strlen(diffname.GetBuffer() + 2);
hdr.fne[hdr.nooffiles + fileno].len2 = strlen(diffname.GetBuffer());
strcpy(hdr.fne[hdr.nooffiles + fileno].filenamesource, diffname.GetBuffer());
strcpy(hdr.fne[hdr.nooffiles + fileno].filenameinarch, diffname.GetBuffer() + 2);
hdr.fne[hdr.nooffiles + fileno].filenamesource[strlen(diffname.GetBuffer())] = NULL;
hdr.fne[hdr.nooffiles + fileno].filenameinarch[strlen(diffname.GetBuffer() + 2)] = NULL;
hdr.fne[hdr.nooffiles + fileno + 1].filenamesource = new char[strlen(basename.GetBuffer()) + 1];
newfilesmemallocated += valallocated = strlen(basename.GetBuffer()) + 1;
hdr.fne[hdr.nooffiles + fileno + 1].filenameinarch = new char[strlen(basename.GetBuffer() + 2) + 1];
newfilesmemallocated += valallocated = strlen(basename.GetBuffer() + 2) + 1;
hdr.fne[hdr.nooffiles + fileno + 1].filenamesource[strlen(basename.GetBuffer())] = NULL;
hdr.fne[hdr.nooffiles + fileno + 1].filenameinarch[strlen(basename.GetBuffer() + 2)] = NULL;
hdr.fne[hdr.nooffiles + fileno + 1].len1 = strlen(basename.GetBuffer() + 2);
hdr.fne[hdr.nooffiles + fileno + 1].len2 = strlen(basename.GetBuffer());
strcpy(hdr.fne[hdr.nooffiles + fileno + 1].filenamesource, basename.GetBuffer());
strcpy(hdr.fne[hdr.nooffiles + fileno + 1].filenameinarch, basename.GetBuffer() + 2);
hdr.fne[hdr.nooffiles + fileno + 1].filenamesource[strlen(basename.GetBuffer())] = NULL;
hdr.fne[hdr.nooffiles + fileno + 1].filenameinarch[strlen(basename.GetBuffer() + 2)] = NULL;
fileno += 2;
}
When I run the program in the debugger I get the variable newfilesmemallocated is around 9MB after end of loop.
The program however allocates around 100MB in the loop as seen side by side in TaskManager.
Your suggestions are appreciated.
Regards,
Ramesh D.
Continue reading...