我有两个基本相同的操作:
insert_bytes(from, count)
delete_bytes(start, stop) -> delete_bytes(from, count)insert_bytes实现示例:
unsigned char* new_bytes = (unsigned char*)malloc((old_length+count)*sizeof(unsigned char));
memcpy(new_bytes, old_bytes, from); // negative value can't go to from here
memcpy(new_bytes+count, old_bytes+from, old_length-from);
return new_bytes+from; // pointer to write有没有什么安全的方法可以在不编写5-6行正/负值检查的情况下将delete_bytes实现为对insert_bytes的调用(具有负偏移量)?
发布于 2011-01-31 08:33:11
不..。你的delete函数不知道之前被误定位了多少。
(from,current_size,delta),这是可行的。
https://stackoverflow.com/questions/4846621
复制相似问题