Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kernelsauce/dstr
Reference counted dynamic strings and string lists for C (C89 compliant).
https://github.com/kernelsauce/dstr
Last synced: about 1 month ago
JSON representation
Reference counted dynamic strings and string lists for C (C89 compliant).
- Host: GitHub
- URL: https://github.com/kernelsauce/dstr
- Owner: kernelsauce
- Created: 2012-12-16T11:17:19.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2013-05-20T19:53:49.000Z (over 11 years ago)
- Last Synced: 2024-10-15T20:05:47.174Z (3 months ago)
- Language: C
- Homepage:
- Size: 483 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
dstr
====Reference counted dynamic string and string containers
Use it to ease the work with strings in C. Doxygen documentation is available by generating it from source.
Author: John Abrahamsen .
Its simple:
```C
dstr *str = dstr_with_initial("concat me");
dstr *str2 = dstr_with_initial(" to me");
dstr_append(str, str2);
printf("%s", dstr_from_dstr_to_cstr(str));
dstr_decref(str);
dstr_decref(str2);
```Containers
----------Implementations of both linked lists, dstr_list, and vectors, dstr_vector, are provided.
It's also simple:
```C
dstr_vector *vector = dstr_vector_new();
dstr_vector_push_back_decref(vector, dstr_with_initial("First string"));
dstr_vector_push_back_decref(vector, dstr_with_initial("Second string"));
while(!dstr_vector_is_empty(vector)){
dstr_print(dstr_vector_back(vector));
dstr_vector_pop_back(vector);
}
dstr_vector_decref(vector);
```
No more memory management is needed. dstr library provides functions for containers
that will either decrement reference or not, depending on usage.
Performance
-----------All benchmarks are done on Ubuntu 11.04 and Lenovo W510.
Strings:
```C
dstr *str = dstr_new();
int i;for (i = 0; i < 1000000; i++){
dstr_append_cstr(str, "concat me onto something...");
}dstr_decref(str);
```Without DST_MEM_CLEAR defined (zero bytes previous used string buffers before
freeing):Test: test_some_concating ... time used for 1000000 appends: 0 seconds 50 milliseconds. passed
With DST_MEM_CLEAR:
Test: test_some_concating ... time used for 1000000 appends: 0 seconds 660 milliseconds. passed
Vectors:
```C
dstr *str = dstr_with_initial("append me");
dstr_vector *vec = dstr_vector_new();
int i;for (i = 0; i < 1000000; i++){
dstr_vector_push_back(vec, str);
}dstr_vector_decref(vec);
dstr_decref(str);
```Without DSTR_MEM_SECURITY (boundary protection for operations get/set/remove operations):
- Test: test_vector_append_speed ... time used for 1000000 push_back to vector: 0 seconds 60 milliseconds. passed
- Test: test_vector_append_speed_no_prealloc ... time used for 1000000 push_back to vector: 0 seconds 70 milliseconds. passed
- Test: test_vector_append_front_speed ... time used for 20000 push_front to vector: 2 seconds 140 milliseconds. passedWith DSTR_MEM_SECURITY defined:
- Test: test_vector_append_speed ... time used for 1000000 push_back to vector: 0 seconds 70 milliseconds. passed
- Test: test_vector_append_speed_no_prealloc ... time used for 1000000 push_back to vector: 0 seconds 70 milliseconds. passed
- Test: test_vector_append_front_speed ... time used for 20000 push_front to vector: 2 seconds 140 milliseconds. passedLists:
- Test: test_list_speed ... time used for 1000000 insertion to list: 0 seconds 110 milliseconds. passedLicense
-------Copyright 2012 John Abrahamsen
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.