如何从另一个文件释放内存?

问题描述

我正在学习动态内存分配。

我写了几行以了解指针,表和内存分配的工作方式。我有一个>>> from couchbase.cluster import Cluster Traceback (most recent call last): File "<pyshell#0>",line 1,in <module> from couchbase.cluster import Cluster ModuleNotFoundError: No module named 'couchbase' >>> import couchbase Warning (from warnings module): File "C:\Users\enora\anaconda3\lib\site-packages\couchbase_core\__init__.py",line 43 warnings.warn("Couldn't import SSL,TLS functionality may not be available") UserWarning: Couldn't import SSL,TLS functionality may not be available Traceback (most recent call last): File "<pyshell#1>",in <module> import couchbase File "C:\Users\enora\anaconda3\lib\site-packages\couchbase\__init__.py",in <module> import couchbase_core._bootstrap File "C:\Users\enora\anaconda3\lib\site-packages\couchbase_core\__init__.py",line 45,in <module> import couchbase_core._libcouchbase as _LCB ImportError: DLL load Failed: Le module spécifié est introuvable. 函数,但是我不知道将malloc函数放在哪里?

main.c:

free

allocation.c:

    #include <stdio.h>
    #include <stdlib.h>

    #include "allocation.c"

    int main(void)
    {

        int count = 5;
        int initValue = 2;
        int increment = 3;

        int *result = arithmeticSequence(count,initValue,increment);
        printf("Adresse de mon pointeur : %p\n",result);

        for(int i=0 ; i < count ; i++)
        {
            printf("[%d]",*result);
            result++;
        }
        return 0;
     }

解决方法

这是对象所有权的问题。无论对象(或指针)拥有什么函数(或类,模块等),都必须确保在所有可能的条件下尽快释放(或销毁)该对象(或指针),直到没有该对象(或指针)为止。需要更长的时间。确保所有者以外的其他任何人都不能释放它也很重要。

作为程序员,您需要确定每个指针的最佳“所有者”。在此程序中,最好的选择是 { std::packaged_task<int(int,int)> f { add }; std::future<int> fut = f.get_future(); } // fut goes out of scope,but there is no point // in waiting in its destructor,as it cannot complete // because as `f` is not given to any executor. 函数。