c - 重新分配时如何添加空间或内存
问题描述
在这段没有注释掉的代码中,我想添加到内存中。这将是非常糟糕的措辞。基本上,我希望能够将元素添加到列表中,但我不知道具体如何。如何增加我正在重新分配的空间我做了类似的事情 (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
}*/
解决方案
推荐阅读
- javascript - 顺序执行操作时 Rxjs 与 concat 运算符有关的问题
- jquery - 用于滚动条的引导模态 jquery 函数和动态模态高度在 Firefox 上无法正常工作
- python - 为什么 Pandas Series.isin 适用于字符串而不适用于数字?
- python - Python - ETF 每日数据网络抓取
- git - git pull --rebase -- 是远程重新定位到本地分支吗?
- c# - WCF 无法将文件作为流返回
- postgresql - 错误:postgres 上最后一个预期列之后的额外数据
- r - ggplot2 + geom_point + 气泡与大小成比例(错误“离散值提供给连续比例”)
- html - 如何将图像与多个段落居中
- javascript - 将超时添加到循环