|
Chris Losinger wrote:
maybe i'm wrong. i hope so. i'd like to see what it's like.
*grin*
Well, I'd just presume that someone who asks if they need to delete something they did not allocate probably won't understand what 'allocate' means.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
You can only delete the variables you initialised in pointers. This won't work:
int i;
i = 0;
ExternalFunction(i);
delete i; // WONT WORK !!!
non pointers are deleted for you when they go out of scope.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Ah okay
Thats even better, so basically delete anything that is a pointer otherwise if it is just a variable inistialised on the stack i leave it to go out of scope
Peter
|
|
|
|
|
Right i just read Chris Losinger second post and fully get it now in which case i have doen the right thing cause i already deallocted all pointers. The biggest thing was i basically have structures initalised not allocated and was wondering if they needed deleting but obviously since they are initialized and not allocated i just leave them to go out of scope.
I have one other question though my structure contains pointers at the moment i am doing delete[] on the pointers in teh structure and then settign the pointer to null and letting the rest go out of scope. Is this the right thing to do?
Peter
|
|
|
|
|
"delete [] ptr;" when you allocate an array (CString *ptr = new CString[100]). otherwise use "delete ptr;".
-c
<font size=-2>
o(int O){putchar(O);}main(){float _[8],O,I=.05;char l;for(_[6]=15;_[6]<':';o
(10),_[5]=-'$'*I+_[6]++*I)for(_[7]=-5;_[7]<'@';_[4]=-'('*I+_[7]++*I,o(l?'?':':'))
for(*_=O=0,l=1;++l&&((_[2]=*_**_)+(_[3]=O*O)<4);O=*_*O+_[5]+O**_,*_=_[2]-_[3]+_[4]);}</font>
|
|
|
|
|
I'm trying to optimize a function. I have an implementation in a static library that i'm using as a reference and another built into my app that i'm working on. I'm not recompiling the static lib, just linking to it.
The test code looks like this:
dwStart = GetTickCount();
for (z=0;z<reps;z++)
{
Fn(params);
}
dwStop = GetTickCount();
Trial 1:
compiled in release mode with "Max Speed" optimizations
run 1000 reps of each over the same data set
New implementation : 2.45 sec
Reference implementation : 6.41 sec
So, I'm doing good. I've halved the speed of the reference.
Trial 2:
compiled in release mode with "Default" optimizations
run 1000 reps of each over the same data set
New implementation : 3.45 sec
Reference implementation : 5.70 sec
So, as expected, the new function is slower without the max-speed optimizations. but, the reference implementation, the one in the static libs that i'm not recompiling has gotten faster when i changed optimization settings. Errrr... WTF??
any ideas?
-c
<font size=-2>
o(int O){putchar(O);}main(){float l[8],O,I=.05;char _;for(l[6]=15;l[6]<':';o
(10),l[5]=-'$'*I+l[6]++*I)for(l[7]=-5;l[7]<'@';l[4]=-'('*I+l[7]++*I,o(_?'?':':'))for
(*l=O=0,_=1;++_&&((l[2]=*l**l)+(l[3]=O*O)<4);O=*l*O+l[5]+O**l,*l=l[2]-l[3]+l[4]);}</font>
|
|
|
|
|
Chris Losinger wrote:
the one in the static libs that i'm not recompiling has gotten faster
Did you reboot in between tests? I always do that, to make sure all caches are emptied. For example, the 6.41s run might have read data from disk, which was then cached when subsequent tests ran, resulting in the 5.7s time later.
--Mike--
Buy me stuff!
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
nope. if i switch back to the max speed optimizations, it goes back to the first set of numbers. it's consistent.
-c
<font size=-2>
o(int O){putchar(O);}main(){float l[8],O,I=.05;char _;for(l[6]=15;l[6]<':';o
(10),l[5]=-'$'*I+l[6]++*I)for(l[7]=-5;l[7]<'@';l[4]=-'('*I+l[7]++*I,o(_?'?':':'))for
(*l=O=0,_=1;++_&&((l[2]=*l**l)+(l[3]=O*O)<4);O=*l*O+l[5]+O**l,*l=l[2]-l[3]+l[4]);}</font>
|
|
|
|
|
It's hard to know without more info about that Fn function and the parms it is accepting. Change the static lib implementation to a do-nothing function, so that you will be basically measuring the cost of doing the function call --maybe this sheds some light on the problem.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
FYI, here are the parameters:
<br />
void FnNew(const BYTE *pIn, const int inW, const int inH, BYTE *pOut, const int outW, const int outH, const int bpp)<br />
the static lib function has essentially the same params, except that they aren't "const" - they are treated as const, but not labelled as such. i tested this angle and got the same results, const or not.
-c
<font size=-2>
o(int O){putchar(O);}main(){float _[8],O,I=.05;char l;for(_[6]=15;_[6]<':';o
(10),_[5]=-'$'*I+_[6]++*I)for(_[7]=-5;_[7]<'@';_[4]=-'('*I+_[7]++*I,o(l?'?':':'))
for(*_=O=0,l=1;++l&&((_[2]=*_**_)+(_[3]=O*O)<4);O=*_*O+_[5]+O**_,*_=_[2]-_[3]+_[4]);}</font>
|
|
|
|
|
What happens if you replace the static lib "i.e. the reference" implementation with a do-nothing function? Still having worse results in "Max speed"?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
actually, no.
i had to make a new static lib to test this (don't have the source to the other lib with me). but, the do-nothing function with 100000000 reps takes the same amount of time regardless of how the calling app is optimized.
hmm.
-c
<font size=-2>
o(int O){putchar(O);}main(){float _[8],O,I=.05;char l;for(_[6]=15;_[6]<':';o
(10),_[5]=-'$'*I+_[6]++*I)for(_[7]=-5;_[7]<'@';_[4]=-'('*I+_[7]++*I,o(l?'?':':'))
for(*_=O=0,l=1;++l&&((_[2]=*_**_)+(_[3]=O*O)<4);O=*_*O+_[5]+O**_,*_=_[2]-_[3]+_[4]);}</font>
|
|
|
|
|
Maybe I didn't made myself clear enough... I'm asumming the do-nothing function still accepts the whole lot of parameters (even though it does nothing with them), right?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
yes. it's the same function signature - just nothing in the function.
-c
<font size=-2>
o(int O){putchar(O);}main(){float _[8],O,I=.05;char l;for(_[6]=15;_[6]<':';o
(10),_[5]=-'$'*I+_[6]++*I)for(_[7]=-5;_[7]<'@';_[4]=-'('*I+_[7]++*I,o(l?'?':':'))
for(*_=O=0,l=1;++l&&((_[2]=*_**_)+(_[3]=O*O)<4);O=*_*O+_[5]+O**_,*_=_[2]-_[3]+_[4]);}</font>
|
|
|
|
|
Chris Losinger wrote:
FYI, here are the parameters:
void FnNew(const BYTE *pIn, const int inW, const int inH, BYTE *pOut, const int outW, const int outH, const int bpp)
That explains it. Seven stack parameters using the IA32 architecture can be nothing but disaster. You wouldn't gain much by using "register" calling conventions either, since at four (or rather three in C++ functions) GPR's the optimizer can't actually help.
Try creating a struct that wraps your paramaters and do some re-testing. I'm sure you'll get the speed up again.
Note: Using MSVC you'd have to create auto-variables at the callee's site if you're using them more than once, else the MSVC optimizer often don't "cache" the values in registers, it frequently reloads them from the pointed-to object. I.e. do
void FnNew(const* pSmth)
{
const int inW = pSmth->inW;
... use inW multiple times ...
}
|
|
|
|
|
It could well be the kernel process scheduler. Well not so much that but say another program starts having a few page faults, in 5 seconds the kernel has switched so many threads and processes that this kind of thing could be affecting your timings. The best way is to do this over a longer period, say 30-60 seconds. As well as that make sure you have things like background file indexing etc turned off. It all makes a difference, and it could be that your thread is not getting its share of the time it wants. Ultimately the scheduler is based on heuristics that allow it to tune itself, and while its accurate most of the time, there’s not reason while it could not mess up for a second or two. Have your tried repeating the same thing – could be asking a stupid question. I’ll shut up.
|
|
|
|
|
sadly, the times are totally consistent and reproducable.
-c
<font size=-2>
main(){float _,l,O,I,o,x;char i;for(x=-1;x<1;x+=.05,putchar(10))
for(o=-2;o<.9;o+=.05,putchar(i?'?':':'),_=l=O=I=--(i=1))for
(;((O=_*_)+(I=l*l)<4)&++i;l=_*l*2+x,_=O-I+o);}
</font>
|
|
|
|
|
Hi,
As title.
I know that there are a few ZIP compression libraries either
freely or commercially available.
But I couldn't find RAR compression ones, simple source
codes, or even books about this compression algorithm
as I have the needs to handle RAR files in my program.
So, just wondered if someone knows it. Thanks
|
|
|
|
|
ykliu wrote:
But I couldn't find RAR compression ones, simple source
codes, or even books about this compression algorithm
as I have the needs to handle RAR files in my program.
<irony>
How odd, a commercial compression library with a proprietary compression algorithm isn't freely available.
Serisouly, since its proprietary you won't find any free implementations of it.
For free implementations I'd say that for fast compression I recommend you have a look at LZO. For reasonable time/space you should probably use zlib. For better compression you should probably have a look at bz2.
|
|
|
|
|
Hi:
I am sort of new to C++.
Suppose I created a CString array of n elements.
CString *someArray;
someArray = newCString[n];
Then further in the code I changed my mind and decided that n was too much and half of that will be enough.
Can I resize the array during run time WITHOUT losing the data in the first half of the array. In VB it's easily achieved using PRESERVE keyword. Is there an alternative in C++?
Thank you.
|
|
|
|
|
No there is not.
The best you can do is to allocate a new buffer, and copy all of the data from the first buffer into the second buffer. Delete the memory from the first buffer, then assign the pointer from the second buffer back to the first.
By the way, the VB method is just more convenient, not more effifient, underneath all of this work is done by VB as well, you just do not have to deal with it.
Good Luck!
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
short answer to this particular question: use CStringArray. you can resize the array all you want.
not as short answer to this particular question: use std::vector<CString>. vectors are dynamic arrays, so you can resize them at will.
but, short answer to the general question "can i resize an array allocated with 'new'?": no.
-c
<font size=-2>
o(int O){putchar(O);}main(){float l[8],O,I=.05;char _;for(l[6]=15;l[6]<':';o
(10),l[5]=-'$'*I+l[6]++*I)for(l[7]=-5;l[7]<'@';l[4]=-'('*I+l[7]++*I,o(_?'?':':'))for
(*l=O=0,_=1;++_&&((l[2]=*l**l)+(l[3]=O*O)<4);O=*l*O+l[5]+O**l,*l=l[2]-l[3]+l[4]);}</font>
|
|
|
|
|
Ok. This is my code, iøm using the CreateDIalog function so i can use my Resource file to design the app:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
ghInstance = hInstance;
ghWnd = CreateDialog (hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, WndProc);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
but when i run the program, nothing appears.
Thanks all!
|
|
|
|
|
I guess you need to call ShowWindow(SW_SHOW) after create.
|
|
|
|
|
Cool it works now. But i can't move the window now... any ideas?
Thanks
|
|
|
|
|