首页 > 解决方案 > 重新分配时如何添加空间或内存

问题描述

在这段没有注释掉的代码中,我想添加到内存中。这将是非常糟糕的措辞。基本上,我希望能够将元素添加到列表中,但我不知道具体如何。如何增加我正在重新分配的空间我做了类似的事情 (something = realloc(blockhead_point, capacity++);) 还是我在想这个错误?

struct blockhead_node{
    int x, y;
    int dx, dy;
    size_t capacity;
    int *data// account 4 mx and my
};


  void add_blockhead_for_mouse(struct blockhead_node * blockhead_list, int v, double mx, double my) // double pointer because we can't modify the lost it self
    {


    int blockhead_pointer = malloc(sizeof(struct blockhead_node) * capacity));
    realloc(blockhead_pointer, capacity);


    /*for (int c = 0; c >= blockhead_list; c++)
    {
        reallc(blockhead_list->size[0] + 1) = blockhead_list->data; //adding memory
        blockhead_list[0][-1] = mx; //add a bkhd to the end of the list

    }
    for (int q = 0; q >= blockhead_list; q++)
    {
        reallc(blockhead_list->size[1] + 1 = blockhead_list->data; //adding memory
        blockhead_list->size[1][-1] = my; //add a blockhead to the end of the list

    }*/

标签: c

解决方案


推荐阅读