win32 api - MultiByteToWideChar 和 WideCharToMultiByte 问题
我需要释放从这些函数中获得的字符串吗?或者系统可能会跟踪它们。同样的问题也适用于 GetCommandLine()。
Do I need to free the strings I get from those functions? Or maybe the system keeps track of them. Same question goes for GetCommandLine().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您负责分配和释放发送到
MultiByteToWideChar
和WideCharToMultiByte
的缓冲区。GetCommandLine
的返回值由 Win32 处理。You are responsible for allocation and deallocation of the buffers sent to
MultiByteToWideChar
andWideCharToMultiByte
.The return value from
GetCommandLine
is handled by Win32.对于 Unicode 转换函数,您需要分配内存来保存转换后的字符串。您负责该内存的寿命。
对于 GetCommandLine,您不需要释放返回的内存块。
一个非常基本的经验法则是,当且仅当您分配了内存时才必须取消分配。
For the Unicode conversion functions you need to allocate memory to hold the converted strings. You are in charge of the lifetime of this memory.
For GetCommandLine you don't need to free the returned block of memory.
A very basic rule of thumb is that you have to deallocate if and only if you allocated the memory.