Closed piperoc closed 10 months ago
Just to make sure, I rewrote the graph class using std::vector
and std::unorderded_map
and I have no errors:
maybe I should use something different that co::hash_map
or learn how to use it correctly...
Reproduced it. Let me see..
@piperoc
sorry, a little busy at work these days.It is a bug in co::vector
due to SSO of std::string
. You may use fastring
instead of std::string
to avoid this problem first. I'll try to make a fix later.
@idealvin awesome! That worked right away. Thank you so much for replying so quickly.
In case some needs it, here's the tests with the fastring
instead of the std::string
to get rid of the error:
@piperoc Fixed in this commit.
@idealvin that works. Thanks!
I wrote a simple graph class using the
co::vector
and theco::hash_map
to use a common adjacency list technique.I then created a unit test like the the other files in your
unitest
source folder.All tests pass but at the very end I get what looks like a memory allocation error (it's probably my mistake in using those structures). I tried to profile it but cannot figure it out.
Here's my class:
file: graph.h
```cpp #ifndef GRAPH_H #define GRAPH_H #include "cout.h" #include "stl.h" #include "log.h" templateand here's the file implementing the tests:
file: graph.h
```cpp #include "co/flag.h" #include "co/cout.h" #include "co/log.h" #include "co/unitest.h" #include "co/fastring.h" #include "co/mem.h" #include "co/graph.h" #includeWhen I run the unit tests I get the following
if I debug it aborts when calling
void _destruct_range
from theco::vector
class (fileinclude/co/vector.h
line 322) as the for loop range that I'm indirectly passing (with the destructor) is probably wrong.call stack
``` [...] libc.so.6!__GI_raise(int sig) (\build\glibc-CVJwZb\glibc-2.27\sysdeps\unix\sysv\linux\raise.c:51) libc.so.6!__GI_abort() (\build\glibc-CVJwZb\glibc-2.27\stdlib\abort.c:79) libc.so.6!__libc_message(enum __libc_message_action action, const char * fmt) (\build\glibc-CVJwZb\glibc-2.27\sysdeps\posix\libc_fatal.c:181) libc.so.6!malloc_printerr(const char * str) (\build\glibc-CVJwZb\glibc-2.27\malloc\malloc.c:5342) libc.so.6!_int_free(int have_lock, mchunkptr p, mstate av) (\build\glibc-CVJwZb\glibc-2.27\malloc\malloc.c:4171) libc.so.6!__GI___libc_free(void * mem) (\build\glibc-CVJwZb\glibc-2.27\malloc\malloc.c:3134) co::vectorSorry for the lengthy description. Thanks for any advice