|
problem is memory full. can't free.
in this sample source below.
so, how can i free memory in struct.
////////////////////////////////////////////////
// begin source
typedef struct
{
char* sztext;
int nindex;
}T_TEST_T;
typedef struct
{
T_TEST_T *pptest;
char* sztext;
int nindex;
}T_TEST;
void testRun( )
{
T_TEST *ptest
ptest = new T_TEST;
ptest->pptest = new T_TEST_T;
for(int n=0;n<100000;n++)
{
ptest->sztext = new char[1024];
strcpy(ptest->sztext, "test one deep step !!!");
ptest->nindex = 777;
ptest->pptest->sztext = new char[1024];
strcpy(ptest->pptest->sztext, "test two deep step ");
ptest->pptest->nindex = 888;
}
// + must used ptest in struct +
if( ptest->sztext != NULL )
delete []ptest->sztext ;
if( ptest->pptest->sztext != NULL)
delete []ptest->pptest->sztext;
if( ptest->pptest )
delete ptest->pptest;
if( ptest )
delete ptest;
// can't free memory..
// end source
////////////////////////////////////////////////////////////////////////
thank's see this ~ waiting your reply.
|
|
|
|
|
|
In your structures, and a method for cleaning the memory and call it before detructing you structure. In general, it's better to add cleaning methods INSIDE your objects than to clean them externally...
|
|
|
|
|
ofcouese i know fact that inside delete.
but my situation is must be storing in struct.
so, want to free struct at outside.
|
|
|
|
|
Your problem can be summarized like:
char *p;
p = new char[16];
p = new char[32];
delete [] p; Do you see the problem? Memory was allocated twice but only deleted once.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
// worng source
char *p;
p = new char[16];
p = new char[32];
delete p; // <- delete []p;
/////////////////////////
and my situation is must be storing in struct.
so, want to free struct at outside.
|
|
|
|
|
You must've missed my point. In your code snippet, you are assigning a new value to ptest->sztext and ptest->pptest->sztext 100,000 times. With only two delete s outside of the for loop, you are going to have 199,998 memory leaks of 1024 bytes each, or roughly 195.3MB! Make sense?
Anonymous wrote:
and my situation is must be storing in struct.
It matters not what you are allocating the memory for (e.g., struct, object, int, array). It's a simple matter of having one delete for each new .
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I want to use tab control in MDI.
My Tab contain Image,Button,Edit..etc.(as use dialog).
Tab control is ok in dialog.
But MDI is not ok.
|
|
|
|
|
I want to use mdi with check control.
My code is following..
if (m_chk==1){MessageBox("Check","Test",MB_OK);}
else{MessageBox("Not Check","Test",MB_OK);}
I check control on or off.
Every time appears MessageBox is "Not Check".
|
|
|
|
|
Hi,
you must have to call UpdateData(TRUE) before calling this code.
This may help you
Sujan
|
|
|
|
|
Hi
I have one in-place Directshow transform filter, and I am currently scratching my head looking for ways for the filter to detect that the user is currently seeking through the file (in lieu of the filter playing continous frames). If the user is currently seeking, I want to reset some variables in my filter. Is there a way to do this?
Thanks!
|
|
|
|
|
I want a little of you advice in a making of a computer program.
Actually i recently made a very simple software. It basically captures the "stock market" transactions. After capturing tractions, the decision of buying or selling is made according to some pre defined formulas. For example
1) If total shares purchased are greater than 50 and and stockmarket opening time is 9:30 AM then sell 23 shares.
2) If stock market opening time is greater than 9:30 then do not buy any share till 11:30 and after 11:30 use formula ABC to get share difference and if difference is negative than buy that share.
There are 11 such conditions defined by our client. We've hardcoded all these condiotions in our source code.
Now the problem is that, these conditions are hardcoded and client daily wants to change conditions or define new conditions. Whenever client wants to enter new condition, it call us, then we add such condition or formula in the source code and then send updated copy.
Now we want to make this generic i.e we want to add new feature so that our client can himself add new condition or change existing at runtime. This is where i require your advice. suppose if you were at my place that what had you done ? Does the solution lies in writing parser/compiler.
Imtiaz
|
|
|
|
|
Hi
With my experience I would model all the possiblity and a create a customizable software. The action to be taken could be defined by the client itself.
Represent all the condition by the some variables. And give interface for the client to present their condition using those variables.
Hope it helps you some way
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
|
bryce wrote:
use a a maths parser
What is Maths Parser? Is is something open source or not. Does it support conditional checks like IF/Else or only expressions. Where can i get more information ?
Imtiaz
|
|
|
|
|
I would not write a parser/compiler. I would consider embedding tcl (http://www.tcl.tk/) or python (http://www.python.org/) if I needed the ability to script. Check the licenses with your lawyer of course. I'm not sure if you need the ability to make things fully programable though. (This is partially my baises though, I don't like Perl or Visual Basic.)
Check how mail programs and firewalls do filters. There are lessions to be learned there, even though they won't all apply. Some mailers have GUIs that make is simple to write filters. I think you want to follow their examples.
Find out from your client what rules they are likely to want. Get them to dream, not everything can be done, but you want to know what they can come up with.
Since they are likely to write rules, make sure every rule as a max dollar amount it applies to before it flags someone to review. They can take the loss of $100 here and there from a broken rule, but if the rule triggures a trade that would cost them $1,000,000 they should review it by hand first. If you can come up with other ways to protect them from themselves do it. (careful here, you want to protect them from mistakes, not annoy them by flaging everything!)
Also make a simulator. Something so that they can make the rules, and test them on. Something other than real money. Perhaps keep a log of last weeks prices, so you can say "if this rule was in effect last week you would have traded ...". Give/recomend some books on software testing. (even if they never read them, at least you tried)
|
|
|
|
|
Do any know where I can find SDK's for creating true type fonts.
Thanks & Regrads,
Deliver
If you have faith in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|
|
|
In Win32 Application I created dyanmicaly two edit boxes with CreateWindowEx(..) with WS_TABSTOP style. I set the focus to first Edit control in the code.
When I run the application two edit boxes are appearing and the focus is set to 1st edit box. When I pressed the tab key the focus not changing to 2nd edit.
Can I get any help, and the reason? Thanks in advance.
Murali.
|
|
|
|
|
Change the z-order of the created edit box. you can use SetWindowPos() for this.
There is no spoon.
mail
|
|
|
|
|
Can you explaine how z-order helps in solving my problem? Can you tell me the signifance of z-order here.
|
|
|
|
|
pEdit2->SetWindowPos(pEdit1,0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
Hope this helps.
There is no spoon.
mail
|
|
|
|
|
Moving focus between controls in a dialog is handled by the Windows dialog manager. If the window containing the controls is not a dialog you will have to handle changing focus yourself in your window procedure. (Assuming this is not an MFC app.)
You would have to process WM_CHAR messages and do the appropriate SetFocus when you get TAB. You would also have to check for the Shift key if you had more than two controls.
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
i have written complete code for this program and it is running almost fine it is just not giving proper display in the last screen in the output.
please help me just reply me so that i will send you the source code files and if you want i can connect through netmeeting to show what is going wrong on the output screen. I am also available on msn as youngashish@hotmail.com
and at yahoo as young_ashish@yahoo.com
please please help me
just reply me so that i can send you the source code files.
|
|
|
|
|
Ok send me the code to azghar_hai@hotmail.com
If you have faith in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|