|
Thank you so much, it worked very well ^_^ , excuse my ignorance still new in this .
|
|
|
|
|
Hi
I try to create my own GroupBox (CButton class with BS_GROUPBOX style) control but that class doesn't get any messages from the mouse: WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_LBUTTONUP and etc.
I can't understand why.
Can anyone help me?
|
|
|
|
|
|
I added to .h
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
and to .cpp
ON_WM_MOUSEMOVE()
...
void CMyGroupBox::OnMouseMove(UINT nFlags, CPoint point)
{
}
That works for simple CButton-derived class but with BS_GROUPBOX style it's not work
|
|
|
|
|
|
Thanks a lot
The way with WM_NCHITTEST handler works!
|
|
|
|
|
i had already developed the program but it's not working properly. i am having some confusion on array memory manegment and array arrangement so please do help me to develop this program...
Thank you
|
|
|
|
|
You first need to show us the code that is not working, and explain where the problem is.
|
|
|
|
|
First ask yourself: what constitutes a duplicate value?
Instead of going straight to the keyboard to solve this problem, sit at the table with a deck of cards. Ignoring the suits, lay all (or a portion) of the cards out in front of you. Now working from right to left, work through each card and see if it qualifies as a duplicate per your answer from above. This might look something like:
Compare card 52 to card 51. If they match, remove card 52 from array.
Compare card 51 to card 50. If they match, remove card 51 from array.
Compare card 50 to card 49. If they match, remove card 50 from array.
...
Compare card 1 to card 0. If they match, remove card 1 from array.
An alternative would be if the card is unique, move it to a separate array. Now you can destroy the original array and be left with an array of just unique items.
There are other ways to skin this cat, but it's really going to boil down to what makes the most sense to you. You might not initially have the most elegant or efficient solution as others on this board could come up with, but those skills come in time.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I made a image comparison program, but an exception error appeared at iteration number 1350, the code is here:
void compara_face(__int16 cara1[YMAX][XMAX],__int16 centro1[2*3],__int16 cara2[YMAX][XMAX],__int16 centro2[2*3],__int16 zoom_level,__int16 num_filtros,double error[2])
{
error[0]=error[1]=1e199;
if (zoom_level >DMAX) { printf("\nERROR en compara_face() zoom_level =%i > %i",zoom_level ,DMAX);return; }
if (num_filtros>FMAX) { printf("\nERROR en compara_face() num_filtros=%i > %i",num_filtros,FMAX);return; }
double coef[6];
trasformada3p_hallacoef(centro1,centro2,coef);
__int16 (*filtro2)[6]=new __int16[num_filtros][6];
__int16 (*filtro3)[6]=new __int16[num_filtros][6]; ERROR IS HERE!!!!
__int16 d=DELTA[zoom_level],z=zoom_level;
long i;__int16 x1,y1;
transformada3P_dx(coef,FILTROX[z],filtro2,d,num_filtros);
transformada3P_dy(coef,FILTROY[z],filtro3,d,num_filtros);
error[0]=error[1]=0.0;
for (i=0;i<num_filtros;i++)
{
x1=FILTROX[z][i][0];y1=FILTROX[z][i][1];
error[0]+=fabs( (double)(
(cara1[y1][x1 ]-cara1[y1][x1+ d])* (cara2[filtro2[i][3]][filtro2[i][2]] - cara2[filtro2[i][5]][filtro2[i][4]])-
(cara1[y1][x1+d]-cara1[y1][x1+2*d])* (cara2[filtro2[i][1]][filtro2[i][0]] - cara2[filtro2[i][3]][filtro2[i][2]]) ));
x1=FILTROY[z][i][0];y1=FILTROY[z][i][1];
error[1]+=fabs( (double)(
(cara1[y1 ][x1]-cara1[y1+ d][x1])* (cara2[filtro3[i][3]][filtro3[i][2]] - cara2[filtro3[i][5]][filtro3[i][4]])-
(cara1[y1+d][x1]-cara1[y1+2*d][x1])* (cara2[filtro3[i][1]][filtro3[i][0]] - cara2[filtro3[i][3]][filtro3[i][2]]) ));
}
delete[] filtro2,filtro3;
}
The error appear in the second "new" command. The program uses a lot of RAM, perhaps I need to compiler or linker to use more ram or allocate memory as static instead dynamic.
The program uses about 2 gigabytes
modified 17-Dec-15 5:44am.
|
|
|
|
|
Your system has no more free RAM. Then the only option is to provide more (add RAM or use a different system which has more). There are no compiler or linker options to prevent the exception and using static memory would not help (it is even worse).
[EDIT]
See this StackOverflow thread about the 2 GB limit: http://stackoverflow.com/questions/5686459/what-is-the-maximum-memory-available-to-a-c-application-on-32-bit-windows[^]
But the allocation where the exception occurs does not ask for a large amount of memory. The max. allocated size is 786 kB (16-bit int * 6 * sizeof(int16)). So you should check if the other places where the really large amounts of memory are allocated can be optimized (e.g. by deleting memory immediately when it is no longer neeeded).
|
|
|
|
|
Thank you Jochen.
I used the windows task manager and I found that the delete command does not frees memory. I changed to static allocation and the program run.
I used a VS2008 sp1, but perhaps I have to add any hotfixes.
If someone is interested in the problem I can try also in VS2015 to see what happens
modified 17-Dec-15 6:51am.
|
|
|
|
|
Thank you for your feedback.
But why should delete not free memory? Did you always use the correct form (delete [] for arrays)?
|
|
|
|
|
As can you see in the code I used delete[], I used also delete only and in release mode but the memory was not freed.
By using static allocation my program used 26MB only.
I tried this simple code and worked fine:
#include <stdio.h>
void main()
{
long i,size=((long)(1024L*1024L*50L/6L))*6;
for (i=0;i<100;i++)
{
__int16 (*memory)[6]=new __int16[1024L*1024L*50L/6L][6];
memory[1024L*1024L][5]=132;
delete memory;
printf("\nAllocated and deallocated %li MB",i*(size/1024L)*sizeof(__int16)/1024);
}
printf("\n=== FIN ===");
getchar();getchar();
}
Perhaps the visual studio could not deallocate the memory to be reused because any operation reason
|
|
|
|
|
I saw that you used the array form there. My suggestions was to check it elsewhere in your program.
When checking it again I saw that you use this:
delete[] filtro2,filtro3;
Asking myself if this is allowed, I searched and found that it is allowed but is a so called placement delete which effectively does nothing.
Use this instead and try your original code:
delete[] filtro3;
delete[] filtro2;
|
|
|
|
|
YES, you are right
Thank you very much, you solved me a lot of problems
|
|
|
|
|
I think we have both learned something new today (I did not know the placement delete before) 
|
|
|
|
|
More than the two of you learned something new.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
About using the task manager>process window, I found that there is an error of memory used varies about 4k from one run to the following, so it can be used to see memory variations in debug sessions taken in account that.
I used it to run the following very simple code:
#include <stdio.h>
void program_good()
{
char *memory=new char[10000L*1024L];
memory[1024]=' ';
delete[] memory;
}
void program_bad()
{
char *memory=new char[10000L*1024L];
memory[1024]=' ';
}
void main()
{
double x[10];
char ptr0[1024];
program_good();
char ptr1[1024];
printf("\nMemory diference=%li",(long) (&ptr1-&ptr0-1024));
program_bad();
char ptr2[1024];
printf("\nMemory diference=%li",(long) (&ptr2-&ptr1-1024));
printf("\n=== FIN ===");
getchar();getchar();
In the task manager I found that my "Prueba.exe" memory usage was:
step #1 and #2: 484k
step #3: 10508k
step #4: 484k
step #5: 492k (I do not know why printf used 8kb)
step #6: 10516k
As result the calling of the program_bad() leaks 10Mb plus 32kb
So the task manager is not an exact tool but can help
|
|
|
|
|
Good to know, but I was refering more to Jochen's 'discovery' of placement delete.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Good catch. 
|
|
|
|
|
Member 11988283 wrote:
I used the windows task manager and I found that the delete command does not frees memory. The numbers you see in Task Manager are almost, but not quite completely, useless for telling how much of your program's memory is in use. If you see it shrink, fine, but if you don't, it is not necessarily bad.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
task manager isn't going to help you much.
at a high level, it works something like this:
when you allocate memory, it comes from your process's heap - if that heap is too small, it allocates more from the OS (up to the OS's per-process memory limit). when you free memory, it typically goes back to the process's heap, not back to the OS. this happens because it's common for a program to allocate/free the same amount of memory over and over, and it's quicker to just grab memory from the process's heap than to get the OS involved. so, under normal situations, your heap rarely shrinks. it typically grows and grows until it gets big enough to keep your program satisfied. it's only when your app shuts down that the heap memory is finally and completely released back to the OS.
if the OS itself is running low on memory, it will start grabbing unused heap memory from your process. so sometimes you'll see Task Manager show a drop after a large free - some other process needs a large contiguous block and the OS hands it over. but don't count on that.
|
|
|
|
|
I tried with VS2008 and it fails to allocate more than 2GB becaus delete command does not free memory.
Using VS2015 (x86) fails also
Using VS2015 x64 fails but more than 4GB are allocated
|
|
|
|
|
Hi all,
I have a project written with VS6.0 C++ (MFC). In that project we use WININET to accomplish FTP download files from server; now we are asked to use Secured FTP (SFTP).
As I read from sites and forums, WININET doesn't support SFTP. My question: is there a third party that I could include in my project to be able to use SFTP?
Thank you in advance.
"The Only Limit Is Only Your Imagination."
|
|
|
|