仿制缓冲重新presentation无效*或字符*? [英] void* or char* for generic buffer representation?
本文介绍了仿制缓冲重新presentation无效*或字符*?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设计一个Buffer类,其目的是重新present的内存块。
I'm designing a Buffer class whose purpose is to represent a chunk of memory.
我的基础缓冲区是的char *
(当然,一个的boost :: shared_array<焦炭>
实际上,但是这并不重要)。
My underlying buffer is a char*
(well, a boost::shared_array<char>
actually, but it doesn't really matter).
我被困在决定为我的构造函数,选择什么样的原型:
I'm stuck at deciding what prototype to choose for my constructor:
我应该去的:
Buffer(const void* buf, size_t buflen);
或用:
Buffer(const char* buf, size_t buflen);
或者其他什么东西?
Or something else ?
什么是平时成绩,为什么?
What is usually done, and why ?
推荐答案
API接口是用户更加清晰,如果缓冲区有void *的类型,有串的char *类型。比较memcpy和strcpy函数的定义。
API interface is more clear for user, if buffer has void* type, and string has char* type. Compare memcpy and strcpy function definitions.
这篇关于仿制缓冲重新presentation无效*或字符*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文