|
System does not delete or free old memory block, becuse if I work in a cycle('For') I get System Memory Leak.
|
|
|
|
|
System does not delete or free old memory block...
Yes it does. Probably you're experiencing problems due to your mixing of new and realloc . Try using malloc instead of new .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I do not mix between New & Delete and malloc realloc & free
and still I got System Memory Leak.
I have tried diffrent of variations.
|
|
|
|
|
I strongly doubt you've discovered in realloc . Try to downsize your program to a postable sample and, if the error persists, publish the sample here.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I am allocating a vector of double's, and inside a loop this vector is growing each cycle. So I need to realloc for the new size, but after a few cycles the memory is full.
The sample i post the fisrt time is the sample you need. Just put it in a 'FOR' loop, and increase the a amount of memory allocation. Let me know if you got a memory leak.
|
|
|
|
|
do a simple test u will know trouble.
call malloc, and new then check the addresses assigned by the two calls.
u will find the number from new is much larger.
new is realy on global.
malloc, even GlobalAllocPtr is not.
includeh10
|
|
|
|
|
OK, I think I know ehere your problem lies. When realloc fails, then it is your responsibility to free the old block. I guess this is the memory leask you're having. This sample reallocates till memory exhaustion taking care of the freeing when the exhaustion occurs:
double *ptr, *ptr_1;
long N=100;
ptr=(double *)malloc(N*sizeof(double));
for(;;){
N*=2;
ptr_1=ptr;
if((ptr=(double*)realloc(ptr, N*sizeof(double)))==NULL){
free(ptr_1);
break;
}
}
Please let me know if this solves your problem.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
this cod u wont to see plias tray
#include <stdlib.h>
#include <stdio.h>
void main(){
double *ptr,*ptr_1;
long N,M,counter,i;
static long x=0;
N=200;
M=20;
counter=20000;// chage counter to 70000 and tray to run programm agein.
ptr=(double*)malloc(N*sizeof(double));
for(i=1;i<=counter;i++){
ptr_1=ptr;
if((ptr=(double*)realloc(ptr,N+i*M*sizeof(double)))==NULL){
printf("memory full %d\n",x);
exit(1);
}
if(ptr_1!=ptr){
x++;
printf(" quontity of nwe memory allocetions %d \n",x);
//free(ptr_1); //?????????
//with out this line the memory qwiqly fill.
//with this line i get Error masege from Windous.
//the length of vector shod be 1200200
}
}
}
|
|
|
|
|
***repost for those of you that don't read the lounge***
Heya everyone, I'm trying to make a few bucks by selling off bits of my library. And since Amazon won't let a lowly Canadian sell their used books through them, I'm doing it on my own.
Have a look here to see if there's anything that grabs your attention.
Books For Sale [new window]
J
|
|
|
|
|
Sorry for the formatting, I can't seem to find the instructions on how to correctly format source code in these messages.
All I'm trying to do is have the title bar text of a SDI application have the usual title plus some right justified text (szReg). I was not able to do it using the CMainFrame OnPaint, so I tried to fudge it by adding spaces between the two strings until the extent of the text was about enough to fill the window width. I think I will need to take into consideration the border size later, but this code doesn't really get it very close. The text ends up quite a bit short of where I wanted it to be. (This is all done in my own UpdateFrameTitleForDocument()).
Thanks.
//The code --
CString szTitle = szText;
TRY{
CWindowDC dc(this);
CRect r;
GetWindowRect(&r);
int nWindWidth = r.Width();
int nSpace = nWindWidth;
szTitle += szReg;
//Acutal width of the title string
int nActualWidth = dc.GetTextExtent(szTitle).cx;
BOOL bStop = FALSE;
CString szSep;
int nCount = 0;
//keep looping until the width of the window
//is taken up by the string. Add spaces between
//the normal title, and the new (right justified)
//text I'm adding:
while (!bStop){
if (nActualWidth < nSpace){
//Not filled up yet, keep adding spaces
//between the strings:
szSep += " ";
szTitle = szText + szSep + szReg;
nActualWidth = dc.GetTextExtent(szTitle).cx;
}
else
bStop = TRUE;
nCount++;
if (nCount > 1000){
//this should not happen
bStop = TRUE;
SetWindowText(szText + " " + szReg);
}
}
SetWindowText(szTitle);
}
CATCH(CResourceException,e){
SetWindowText(szText + " " + szReg);
}
END_CATCH
|
|
|
|
|
You should probably select the correct font in your DC.
Philippe Mori
|
|
|
|
|
Is there an easy way to get the current title bar font?
Thanks for the reply.
|
|
|
|
|
You have to use the SystemParametersInfo function
with the SPI_GETNONCLIENTMETRICS option.
|
|
|
|
|
Use <pre> tags.
CString szTitle = szText;
TRY{
CWindowDC dc(this);
CRect r;
GetWindowRect(&r);
int nWindWidth = r.Width();
int nSpace = nWindWidth;
szTitle += szReg;
int nActualWidth = dc.GetTextExtent(szTitle).cx;
BOOL bStop = FALSE;
CString szSep;
int nCount = 0;
while (!bStop){
if (nActualWidth < nSpace){
szSep += " ";
szTitle = szText + szSep + szReg;
nActualWidth = dc.GetTextExtent(szTitle).cx;
}
else
bStop = TRUE;
nCount++;
if (nCount > 1000){
bStop = TRUE;
SetWindowText(szText + " " + szReg);
}
}
SetWindowText(szTitle);
}
CATCH(CResourceException,e){
SetWindowText(szText + " " + szReg);
}
END_CATCH
Jason Henderson quasi-homepage articles "Like it or not, I'm right!"
|
|
|
|
|
I have a window that contains an ActiveMovie4 control. I set the control window to be 500 x 500 originally, then the video resizes itself to suit the file opened. How can I get this new rect?
I tried GetWindowRect(), but this only gave me the rect that I initially set as 500 x 500. I also tried GetClientRect(), but this did the same thing and moved the dialog box outside of the main window. Please Help!!!
|
|
|
|
|
I return a variant of this type from an ATL server's interface to an ASP script's object obj . len(obj) returns 0, although in a VB test application i can see a correct returned value.
Is this combination a good one? What else could i return, except BSTR?
rechi
|
|
|
|
|
Bogdan Rechi wrote:
len(obj) returns 0,
You are supposed to use LenB instaed of Len for binary data.
|
|
|
|
|
Hi...
I want to insert text between 2 others lines in a text file.
Do I have to recreate this file or not???
Thanks in advance...
Hello World!!!
from Raphaël
|
|
|
|
|
The only way (to the best of my knowledge) is to create a new temporary file with the updated contents and then replacing the old file with this. Writing to a preexisting file works in an overwriting manner, rather than inserting extra space.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I tried the following:
void CMainFrame::OnChecking()
{
CMenu* mmenu = GetMenu();
mmenu->ModifyMenu(ID_CHECKING, MF_BYCOMMAND,ID_CHECKING, " Selection");
Invalidate();
This does change the title to "selection" but only after the second click. The old caption is still visible beneath the new one which looks like its on a button of its own placed over the old button. Please advise.
Thanks,
ns
|
|
|
|
|
Call function DrawMenuBar.
|
|
|
|
|
That was superb! I didnt know it existed! I really appreciate your help. MAny thanks!
ns
|
|
|
|
|
I have developed MFC based MDI application using VC++ 6.0. The application can open multiple documents using the File->Open menu option. Once there are many documents open, it is quite time consuming to close each of the documents one by one. For this reason I would be interested in providing a menu option under Windows popup menu i.e. Windows->CloseAll, that will help the application to close all the child windows at one shot. As an example the VC++ IDE can be referred, that provides this option. Can someone help me find a solution for doing this.
Thanks/Regards,
|
|
|
|
|
This thread discusses a similar problem, namely that of minimizing all child windows. I guess you can use the technique described there to your purposes.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
There is another easy way of doing this by writing the message handler in the CMainFrame class. The code is as follows...
void CMainFrame::OnWindowCloseall()
{
CMDIChildWnd* child = NULL;
while((child = MDIGetActive())!=NULL)
{
if (child)
child->MDIDestroy();
}
}
This will be completely MFC based.
Thanks/Regards,
|
|
|
|