Giter VIP home page Giter VIP logo

Comments (2)

kroggen avatar kroggen commented on July 4, 2024

Unifying the mallocs in create_string:

hw_string* create_string(const char* value)
{
    int length = strlen(value);
    hw_string* str = malloc(sizeof(hw_string) + length);
    if (!str) return 0;
    str->value = (char*)str + sizeof(hw_string);
    memcpy(str->value, value, length);
    str->length = length;
    return str;
}

But to avoid uneeded copying the hw_string could have a free() function pointer so the string can be released after the use. If the string is static then it can be set with HWSTR_STATIC.

Check how this is done with SQLite for the sqlite3_bind_text:
https://www.sqlite.org/c3ref/bind_blob.html
http://stackoverflow.com/questions/1229102/when-to-use-sqlite-transient-vs-sqlite-static

The SQLITE_STATIC and SQLITE_TRANSIENT values are store in the freefn pointer (inside the string struct) and as they have values of 0 and 1 they can be identified as not being a free() function pointer. If the freefn pointer has a valid pointer, then it is called to free the string.

from haywire.

kroggen avatar kroggen commented on July 4, 2024

The http_request struct could have the url and body hw_string already allocated inside the struct instead of using pointers to hw_string. So we decrease from 3 callocs to 1 in create_http_request, and reduce the free() calls in free_http_request.

It could also use pre-allocated hw_strings for the headers (MAX_HEADERS).

from haywire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.