Comments (2)
The lines:
*tail = 0;
zero_pad(tail, circ_buf->element_size);
are suppose to do a "cleanup" after the element was removed from the buffer.
Unfortunately, that is done in very inefficient way.
Because of *tail=0;
the function:
strnlen(s,len);
treats tail
as an empty zero terminated string and will always return 0
forcing zero_pad
function to go via all elem
bytes
for(i=0; i<len; i++)
s[i] = 0;
It is better to replace:
*tail = 0;
zero_pad(tail, circ_buf->element_size);
with faster one line of code
memset(tail, 0, circ_buf->element_size);
which will do exactly the same.
Alternatively, there is nothing wrong with leaving the trace of popped element in the buffer, speeding up the pop operation. In this case there is no need to have that cleanup.
Cleanup can be left to the conditional compilation:
#if ZERO_PAD
memset(tail, 0, circ_buf->element_size);
#endif
from c-utils.
Agreed. Fixed.
from c-utils.
Related Issues (15)
- doesn't compile HOT 1
- This is test issue
- utils.c/hexdup() does not print string when length is exactly 16
- hash_map_free bug HOT 3
- The description for CIRC_GBUF_PEEK and CIRC_GBUF_POP is interchanged HOT 1
- inline functions are not inlined HOT 9
- FILO.c how to make it Circular HOT 1
- Using circular buff with a typedef HOT 1
- push_count and pop_count overflow HOT 10
- Are structures properly stored and retrieved? HOT 1
- warning: ISO C forbids nested functions HOT 2
- circ_gbuf_free_space incorrect HOT 1
- Since `circ_gbuf_free_space` is not thread safe than`circ_gbuf_pop` and `circ_gbuf_pop` are also not thread safe. HOT 4
- Length Bug, or documentation bug HOT 1
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 c-utils.