Click here to Skip to main content
15,915,319 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i create a dynamic library in following manner

1.usage of dynamic library is allocate a memory for the pointer

2.usage of the mian program is to delete the pointer memory that are allocated in the dynamic library function.. that following coding i used..

while running the program it produce the run time error..

dynamic library coding is:
DYLIB_API int* fun(void)
{
printf("i am the funciton in the dynamic lib\n");
p=new int[1000];
return p;
}

main funtion coding is:

int main(int argc, char* argv[])
{
int *p1;
p1=fun();
free(p1);
return 0;
}


please can you help me ..
Posted

1 solution

Before you get any advice on your problem, I must warn you about some problems that may cause some experts to avoid communicating with you.

I noticed that you got a number of recommendations to avoid allocating memory in one executable module and deallocating in another one. You asked 5 (five) very similar questions in a row. You seem to systematically ignore the recommendations. More than that, I offered you a stricter rule for memory allocation and deallocation.

Any person would be interesting in helping you if this effort produces some result. Not only you not following the recommendations, you do not express any concern about it. If you doubt that the recommendation is valid or useful, you should express you doubt by commenting the solution. Instead of doing this, you simply ignore it and simply repeat the same wrong idea in another question in a slightly different form.

You should consider my recommendations in the second paragraph above (which simply repeats previous recommendations you already got before) as a solution. Without accepting it and changing your approach to memory allocation your further question will not have any sense. If you need deeper explanations of it or don't understand the answers — this is a different story; but in this case you should explain your concerns.

Please understand that anyone expect honest and responsible behavior from a person receiving help, otherwise there are no reasons or motives for help.

If you disagree with anything I say, you should explain why. But first of all you should explain: what would be the reasons for anyone to help you.

Thank you for your understanding,
—SA
 
Share this answer
 
Comments
Timberbird 7-Jul-11 2:56am    
Agreed. In fact, I've had some "not again" moments when discovering new - same -question from the OP :)
Sergey Alexandrovich Kryukov 8-Jul-11 1:27am    
Thank you. OP sent the explanation (probably removed) that the reason is that he is working only at one task, so the questions are repeated, but that does not justify his "method" and leads nowhere, that is the problem.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900