![]() |
gethostbyname() ---- Delete Resulting Pointer?
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? |
Re: gethostbyname() ---- Delete Resulting Pointer?
On Dec 6, 10:36 am, aj <a...@bookac.com> wrote:
> 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? There is no 'new' or 'delete' in the C language. gethostbyname is not defined by the C standard. -- Fred Kleinschmdit |
Re: gethostbyname() ---- Delete Resulting Pointer?
On Dec 6, 1:36 pm, aj <a...@bookac.com> wrote:
> 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? 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 |
Re: gethostbyname() ---- Delete Resulting Pointer?
On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.com> wrote:
> On Dec 6, 1:36 pm, aj <a...@bookac.com> wrote: > > > 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? > > 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. |
Re: gethostbyname() ---- Delete Resulting Pointer?
aj <aj@bookac.com> writes:
> 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? You are doubly off-topic. delete in C++, not C, and gethostbyname is a *nix function. If you want to post somewhere, I'd choose comp.unix.programmer, but man gethostbyname would be quicker (the delete is wrong, BTW). -- Ben. |
Re: gethostbyname() ---- Delete Resulting Pointer?
On Dec 6, 2:23 pm, aj <a...@bookac.com> wrote:
> On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.com> wrote: > > > > > On Dec 6, 1:36 pm, aj <a...@bookac.com> wrote: > > > > 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? > > > 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. You're welcome. After all, what else is comp.lang.C here for, but to *not* discuss COBOL, JAVA, C++, .NET, C#, how to tune your car, oriental cooking, and observance of the Jewish faith? |
Re: gethostbyname() ---- Delete Resulting Pointer?
"aj" <aj@bookac.com> schrieb im Newsbeitrag
news:821a499a-9d57-44cb-9330-fcd7b3ae6342@s36g2000prg.googlegroups.com... >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? for gethostbyname() ask in comp.unix.programmer, it's not topical here for new/delete ask in comp.lang.c++ as neither exists in C, although I think that a delete without a corresponding new won't work. Bye, Jojo |
Re: gethostbyname() ---- Delete Resulting Pointer?
"aj" <aj@bookac.com> schrieb im Newsbeitrag
news:35d5bb8d-2d2f-475e-97ef-2de910761df8@e25g2000prg.googlegroups.com... > On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.com> wrote: >> On Dec 6, 1:36 pm, aj <a...@bookac.com> wrote: .... > As usual, you guys are no help, just sticklers for details. > > Thanks for the non-help. And you believe that this statement helps in getting helped? I guess this just helps in getting you plonked... You've been given all help there is, within topicalitiy of this group, which in this case it pointing you to the groups where you might find help Bye, Jojo |
Re: gethostbyname() ---- Delete Resulting Pointer?
On Dec 6, 2:39 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote: > "aj" <a...@bookac.com> schrieb im Newsbeitragnews:35d5bb8d-2d2f-475e-97ef-2de910761df8@e25g2000prg.googlegroups.com...> On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.com> wrote: > >> On Dec 6, 1:36 pm, aj <a...@bookac.com> wrote: > ... > > As usual, you guys are no help, just sticklers for details. > > > Thanks for the non-help. > > And you believe that this statement helps in getting helped? I guess this > just helps in getting you plonked... > > You've been given all help there is, within topicalitiy of this group, which > in this case it pointing you to the groups where you might find help > > Bye, Jojo My question wasn't about "delete" or "new". My question was if I am responsible for deallocating the pointer provided by a certain function. I wasn't aware that that particular function, gethostbyname(), isn't in the C standard. Regardless, it is still C syntax, compiled by a C compiler. I will save future (read: all) questions for a more appropriate newsgroup. Sorry you felt the need to plonk me. |
Re: gethostbyname() ---- Delete Resulting Pointer?
aj wrote, On 06/12/07 18:36:
Firstly gethostbyname is not part of standard C so questions about it would be better directed to a group dedicated to your platform such as comp.unix.programmer, but before you do that you should at least do some basic research, such as reading the man page for the function. > 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? Secondly delete C++ and not C. You need to decide which language you are using since there are major differences (delete being one of them) and stick to it and not post questions to do with C++ here. -- Flash Gordon |
| All times are GMT. The time now is 09:47 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.