|
CSDNbuxingma?By the way,poor instead pool
|
|
|
|
|
This program doesn't compile and gives me error "Conficting types of L search" . I ran out of all trials and I am so confused why the heck it gives me this error . I would appreciate your contributions to solve my problem .
the function does front back search of an array, if any number matches it sends back its address.
#include <stdio.h>
int main(void) {
int arr []= {1,2,3,4,5,6,7,8,9,10} ;
int req = 5;
Lsearch(arr,&req,10,4);
return 0;
}
void *Lsearch(void *base,void *key,int n,int elemsize)
{
for(int i = 0 ; i<n;i++)
{
void *elemAddr = (char*)base + i*elemsize ;
if(memcmp(key,base,elemsize)==0) return elemAddr ;
}
return NULL ;
}</pre>
|
|
|
|
|
You failed to include a function prototype at the top of the program thus:
void* Lsearch(void*, void*, int, int);
int main(void) {
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thank you so much, it worked very well ^_^ , excuse my ignorance still new in this .
|
|
|
|
|
Either
a) supply a prototype for Lsearch() before it is called
or
b) put the definition of Lsearch() before the definition of main()
|
|
|
|
|
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
|
|
|
|