gethostbyname()----删除生成的指针? [英] gethostbyname() ---- Delete Resulting Pointer?
问题描述
我有以下代码段。在某些平台上,删除
调用在Linux上可以在删除
调用时进行核心转储(内存转储)。我是否负责删除分配了gethostbyname
的内存?
struct hostent * lHostInfo;
lHostInfo = gethostbyname(ipHost。 c_str());
memcpy(&(lDestAddr.sin_addr),lHostInfo-> h_addr_list [0],lHostInfo-
I have the following snippet of code. On some platforms, the delete
calls works, on Linux, it core dumps (memory dump) at the delete
call. Am I responsible for deleting the memory that gethostbyname
allocated?
struct hostent *lHostInfo;
lHostInfo = gethostbyname(ipHost.c_str());
memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo-
>长度h_length);
>h_length);
删除lHostInfo;
我的印象是除非你没有删除任何东西
个人新'它。这种理论在这种情况下是否正确?
delete lHostInfo;
I am under the impression that you don''t delete anything unless you
personally "new''ed" it. Is this theory correct in this situation?
推荐答案
12月6日上午10点36分,aj< a ... @ bookac.comwrote:
On Dec 6, 10:36 am, aj <a...@bookac.comwrote:
我有以下代码片段。在某些平台上,删除
调用在Linux上可以在删除
调用时进行核心转储(内存转储)。我是否负责删除分配了gethostbyname
的内存?
struct hostent * lHostInfo;
lHostInfo = gethostbyname(ipHost。 c_str());
memcpy(&(lDestAddr.sin_addr),lHostInfo-> h_addr_list [0],lHostInfo-> h_length);
删除lHostInfo;
我的印象是你不会删除任何东西,除非你个人bb个人新它。这种理论在这种情况下是否正确?
I have the following snippet of code. On some platforms, the delete
calls works, on Linux, it core dumps (memory dump) at the delete
call. Am I responsible for deleting the memory that gethostbyname
allocated?
struct hostent *lHostInfo;
lHostInfo = gethostbyname(ipHost.c_str());
memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo->h_length);
delete lHostInfo;
I am under the impression that you don''t delete anything unless you
personally "new''ed" it. Is this theory correct in this situation?
C语言中没有''new''或''delete''。
gethostbyname不是由C标准定义。
-
Fred Kleinschmdit
There is no ''new'' or ''delete'' in the C language.
gethostbyname is not defined by the C standard.
--
Fred Kleinschmdit
12月6日,1 :下午36点,aj< a ... @ bookac.comwrote:
On Dec 6, 1:36 pm, aj <a...@bookac.comwrote:
我有以下代码片段。在某些平台上,删除
调用在Linux上可以在删除
调用时进行核心转储(内存转储)。我是否负责删除分配了gethostbyname
的内存?
struct hostent * lHostInfo;
lHostInfo = gethostbyname(ipHost。 c_str());
memcpy(&(lDestAddr.sin_addr),lHostInfo-> h_addr_list [0],lHostInfo-> h_length);
删除lHostInfo;
我的印象是你不会删除任何东西,除非你个人bb个人新它。这种理论在这种情况下是否正确?
I have the following snippet of code. On some platforms, the delete
calls works, on Linux, it core dumps (memory dump) at the delete
call. Am I responsible for deleting the memory that gethostbyname
allocated?
struct hostent *lHostInfo;
lHostInfo = gethostbyname(ipHost.c_str());
memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo->h_length);
delete lHostInfo;
I am under the impression that you don''t delete anything unless you
personally "new''ed" it. Is this theory correct in this situation?
对不起,但C没有
- 一个名为delete的关键字,
- a关键字叫做new
- 一个名为gethostbyname的标准函数()
- 标准结构叫做hostent
我怀疑您正在编写C ++代码(您提及new和
" delete"以及您在示例代码中使用方法调用),这是
comp.lang.c中的偏离主题
您可能想在comp.lang.c中讨论这个主题。
HTH >
-
Lew
Sorry, but C does not have
- a keyword called "delete",
- a keyword called "new"
- a standard function called gethostbyname()
- a standard struture called hostent
I suspect that you are writing C++ code (your mention of "new" and
"delete", and your use of method calls in your example code), which is
off-topic in comp.lang.c
You probably want to discuss this topic in comp.lang.c++
HTH
--
Lew
12月6日下午2:14,Lew Pitcher< lpitc ... @ teksavvy .comwrote:
On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:
12月6日下午1:36,aj< a ... @ bookac.comwrote:
On Dec 6, 1:36 pm, aj <a...@bookac.comwrote:
我有以下代码片段。在某些平台上,删除
调用在Linux上可以在删除
调用时进行核心转储(内存转储)。我是否负责删除gethostbyname
分配的内存?
I have the following snippet of code. On some platforms, the delete
calls works, on Linux, it core dumps (memory dump) at the delete
call. Am I responsible for deleting the memory that gethostbyname
allocated?
struct hostent * lHostInfo;
lHostInfo = gethostbyname(ipHost.c_str());
memcpy(&(lDestAddr.sin_addr),lHostInfo-> h_addr_list [0],lHostInfo-> h_length);
struct hostent *lHostInfo;
lHostInfo = gethostbyname(ipHost.c_str());
memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo->h_length);
delete lHostInfo;
delete lHostInfo;
我的印象是你不会删除任何东西,除非你个人bbbb ;它。这种理论在这种情况下是否正确?
I am under the impression that you don''t delete anything unless you
personally "new''ed" it. Is this theory correct in this situation?
很抱歉,但C没有
- 一个名为delete的关键字,
- a关键字叫做new
- 一个名为gethostbyname的标准函数()
- 标准结构叫做hostent
我怀疑您正在编写C ++代码(您提及new和
" delete"以及您在示例代码中使用方法调用),这是
comp.lang.c中的偏离主题
您可能想在comp.lang.c中讨论这个主题。
HTH >
-
Lew
Sorry, but C does not have
- a keyword called "delete",
- a keyword called "new"
- a standard function called gethostbyname()
- a standard struture called hostent
I suspect that you are writing C++ code (your mention of "new" and
"delete", and your use of method calls in your example code), which is
off-topic in comp.lang.c
You probably want to discuss this topic in comp.lang.c++
HTH
--
Lew
像往常一样,你们没有帮助,只是坚持细节。
感谢您的帮助。
As usual, you guys are no help, just sticklers for details.
Thanks for the non-help.
这篇关于gethostbyname()----删除生成的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!