使用libary分配和释放指针的内存 [英] hwo to allcoate and deallocate memory of pointer using libary

查看:108
本文介绍了使用libary分配和释放指针的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动态库代码:

Dynamic lib code:

DYNAMICLIB_API int* aa1(void)
{
    int *a1;
    a1=(int*)malloc(sizeof(int));
    printf("Interger created\n");
    printf("bye");
    printf("good");
    printf("memory created");
     return a1;
}


我的主要功能代码:


my main function code:

int main(int argc, char* argv[])
{
    int *a1;
    a1=aa1();
    printf("Hello World!\n");
    free(a1);
    return 0;
}



代码产生运行时错误可以为您提供帮助.



that codeproducing run time error can you help me.

推荐答案

您不应分配内存并将其释放到其他模块中,请参见 [
You shouldn''t allocate memory and release it in different modules, see "Allocating and freeing memory across module boundaries"[^].
The simpler solution is making your DLL exporting the ''release memory function''.


这篇关于使用libary分配和释放指针的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆