Ludovic 'Archivist'
Correct but you can tell when an object is destroyed or memory freed.
But sometime, the memory constraints turns into a dangerous bottleneck
Ludovic 'Archivist'
that costs 10k€/y
olli
Btw if you need to duplicate the memory anyway use unique_ptr
Артём
Hello everyone, could you help me please. I'm trying to execute an existing program rec and pass array of strings arr as an argument. All works as needed, but not always: when I enter only '\n', the execv returns -1 and error 14 Bad address. int main(int argc, char ** argv) { vector<string> vMessage; char ch; string tmps; while (ch != '\n') { ch = getchar(); if ((ch == ' ') || (ch == '\n') && (tmps != "")) { vMessage.push_back(tmps); tmps = ""; } else tmps += ch; } char * arr[] = {"QWE11", "Asd22"}; cerr << endl << execv("rec", arr) << endl; perror(""); } I have no idea, how are variables ch, vMessage, tmps related to the function execv with array arr I initialized in my code. Why does thic error occur only in that case?
Ludovic 'Archivist'
Btw if you need to duplicate the memory anyway use unique_ptr
It is not to duplicate that you use shared or GC
olli
It is not to duplicate that you use shared or GC
So you need to synchronize access to the memory anyway?
Ludovic 'Archivist'
Ludovic 'Archivist'
I need things to be read by multiple threads a lot
Ludovic 'Archivist'
and eventually disposed
Ludovic 'Archivist'
if and only if no thread is gonna receive them later
olli
However I don't see how this is not possible using unique_ptr Let the memory owning thread store it in a vector. Pass const pointers to the reading threads. Once you notice no thread is going to receive it and you want to free the memory relaese it from the vector
Ludovic 'Archivist'
aka, not concurrent
Ludovic 'Archivist'
just parallel
olli
Where does the memory come from?
Ludovic 'Archivist'
olli
Some thread (aka owning thread) musr allocate it
Ludovic 'Archivist'
Some thread (aka owning thread) musr allocate it
Yeah, and that thread cannot just hang in wait for the +42 other threads to say they are done
Ludovic 'Archivist'
The "owning thread" have more requests to accept
olli
Yeah of course, While running: Allocate memory put in in vector pass pointer around
Ludovic 'Archivist'
Yeah of course, While running: Allocate memory put in in vector pass pointer around
yeah, and then you get a wonderful mess of who is gonna destroy
Ludovic 'Archivist'
knowing that you don't know which thread is gonna be done last
olli
But how can GC be faster than shared_ptr?
olli
You need to synchronize anyhow
Ludovic 'Archivist'
But how can GC be faster than shared_ptr?
not relying on atomics and memory fences
olli
How does the GC algorithm work?
Ludovic 'Archivist'
and running the least frequently possible
Ludovic 'Archivist'
How does the GC algorithm work?
managing a memory tree from the stacks and parallel mark and sweep
Ludovic 'Archivist'
and generational management
olli
so marking is done in parallel?
Ludovic 'Archivist'
yes
olli
does the same apply for sweeping?
Ludovic 'Archivist'
does the same apply for sweeping?
I do not remember, tried to check but it is not explicitly stated
Ludovic 'Archivist'
libgc is as fast as glibc malloc
olli
because there might be an issue if it is in parallel: how to prevent duplicate deallocation? if not: How to share state between marking and sweeping? (need synchroniziation)
olli
libgc is as fast as glibc malloc
Use custom memory pools, they are as fast as you want them
Ludovic 'Archivist'
olli
but don't free buffers
Its enough to destruct the object. If desired you can manage the buffer on your own
Ludovic 'Archivist'
You know, I don't care about your opinion, GC got me from 12k req/s/core to 22k req/s/core
Ludovic 'Archivist'
compared to shared ptr implementation
olli
it's not about opinions, at laest for me - i just want to understand it
Ludovic 'Archivist'
copy implementation is out of the question when you allocate 16MB buffers
olli
Granted, GC has advantages and disadvantages
Ludovic 'Archivist'
and shared_ptr leaded to tons of memory fences that blocked the CPU cache for long nanoseconds regularly
olli
"A mark-sweep garbage collector traverses all reachable objects in the heap by following pointers beginning with the "roots"" I fail to see how this can be faster than an atomic increment, decrement and comparison Traversing chains of pointers additionally tends to introduce several cache misses
olli
and GC needs to synchronize anyhow
Ludovic 'Archivist'
Ludovic 'Archivist'
and it can perform partial M&S when it can
Ludovic 'Archivist'
It mostly has to go with the use
Ludovic 'Archivist'
and for both reusing memory and allocating lots of big buffers, GC was the best choice
olli
This application doesn't happen to be Open Source?
Ludovic 'Archivist'
I could have used memory pools and a custom allocator to make shared_ptrs in them and implemented my own arena memory management system
Ludovic 'Archivist'
I sell it
olli
I agree passing several shared_ptr around is not ideal.. But i bet there will be a faster method than using GC
Ludovic 'Archivist'
It is a distributed database for trading systems
olli
It is a distributed database for trading systems
all trading systems i am aware of forbid the use of GC
Ludovic 'Archivist'
all trading systems i am aware of forbid the use of GC
The GC is only used by the network layer that parses data in concurent way to then let it be handled by the storage layer
Ludovic 'Archivist'
It is not a quotation engine that should ensure fair transactions, it is closer to MT4 for example
Ludovic 'Archivist'
It should ensure valid transactions
Ludovic 'Archivist'
well, in fact it could be used as a standalone database
.
Hi
.
People
Ludovic 'Archivist'
I am just too lazy to add a real n-tree to it
Ludovic 'Archivist'
Hello
.
Hi
.
Can you creating any game
olli
I am just too lazy to add a real n-tree to it
the gc library you linked uses atomics as well (at least when run in parallel)
Ludovic 'Archivist'
which runs less often than the rest and uses FAR less data than the buffers
Ludovic 'Archivist'
The things is with big data, shared ptrs fences force to load more pages to the CPU cache
Ludovic 'Archivist'
which slow it bucks by bucks
olli
I got curious, I might try to run a benchmark on it in the next couple of days and try to beat the performance G2g now, thanks for the discussion
Ludovic 'Archivist'
and replace it with data you will or not use
Ludovic 'Archivist'
Can you creating any game
I would not say any
Ludovic 'Archivist'
you can only achieve achievable things