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'
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'
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'
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'
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
olli
How does the GC algorithm work?
Ludovic 'Archivist'
and running the least frequently possible
Ludovic 'Archivist'
and generational management
olli
so marking is done in parallel?
Ludovic 'Archivist'
yes
olli
does the same apply for sweeping?
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)
Ludovic 'Archivist'
Ludovic 'Archivist'
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
olli
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
Ludovic 'Archivist'
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'
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
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
Ludovic 'Archivist'
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'
Ludovic 'Archivist'
Ludovic 'Archivist'
you can only achieve achievable things