重新分配时如何添加空间或内存

时间:2018-12-11 00:06:52

标签: c

在此代码中未注释掉,我想添加到内存中。这句话措辞非常糟糕。基本上,我希望能够将元素添加到列表中,但我不知道具体如何。如何增加我要重新分配的空间,我是否做类似的事情(某事= 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

    }*/

0 个答案:

没有答案