Comments (2)
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.
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)
- Default configuration
- haywire_hello_world sometimes segfaults HOT 4
- build fails on OS X 10.11.3 with latest Xcode HOT 2
- [Discussion] Running the benchmarks
- Error building on Windows 2012 R2 Standard (x64) and MVSC2015 HOT 1
- Errors building ib Ubuntu HOT 1
- How about haywire vs h2o or mongoose? HOT 1
- remote peer address
- i run hello world sample on windows(visual studio), when i change thread count > 0, sample can't run HOT 1
- compiling with gyp HOT 3
- Is there any plan to support websocket?
- Should the print body function (hw_print_body) be in Hawyire.h?
- Assertion failed: (server->loop == client->loop) when starting IPC worker threads
- Create a Makefile to replace make.sh HOT 1
- Investigate using mlock
- Split the multi-event loop IPC and REUSEPORT multi-threading from http_server
- Assertion failed: ... does not yet support other types of streams
- pointer being freed was not allocated
- Use the fastest Http Parser picoparser
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from haywire.