Thread: free(host) ?

  1. #1
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708

    Question free(host) ?

    Why don't we free the pointer returned by gethostbyname()?

    I can't see that it's winsock because you could easily call it several times in a program...unless it frees it upon each successive call...it's just bugging me...does anyone here know?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Good question. I'm going to be honest and say that my answer is only my personal conjecture. I think all of the data allocated is part of the global stack that is deallocated with WSACleanup().

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    It may be static, in which case, if you call it twice in a row you'll only have the second result available to you.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    MSDN seems to lean towards the Windows Sockets global stack management idea, and even explicity warns that "the application must never attempt to modify this structure or to free any of its components." It also says that exactly one of these structs is allocated per thread, so you'd think it would reallocate and fill the instance for a specific thread with the information on every successive Winsock call.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

Popular pages Recent additions subscribe to a feed