Pavel
Vlad
Vlad
Vlad
Vlad
So you can divide an array between threads to do work
Vlad
Pavel
Vlad
There's no change to speak of
Pavel
Pavel
If it's a global const then yes it's not a problem
Vlad
Vlad
Pavel
I'm thinking actually about a pattern when you have resources and jobs. And you init jobs with classes that encapsulate access to the resources (either const to read or non-const). Then you can ensure that jobs are being parallelized with respect to that (either by hand, or by computing a graph at runtime that don't allow read and write to the same resource at the same time). But that may be overkill, and not sure that it's even realizable. And yes, then there should be just no other possible way to access the resources rather than through these classes that encapsulate the access.
Pavel
Pavel
Or do you want to garantee there is no waiters on mutex?
Anonymous
Pavel
Or do you want to garantee there is no waiters on mutex?
In general I want to avoid mutexes when possible.
Like when I write code I ensure there's just no way that some data can be read and written at the same time (or even can be accessed only in one place). But I want to ensure that this won't change accidentally in future (since it's just happen to work this way today, when code will grow and be moved around there's a big chance something will break and nobody will notice).
Pavel
Pavel
Just because you can't prove what your code does in general
Pavel
But "in general" is a key point here. With number of constraints it should be doable
Igor🇺🇦
Diego
Diego
I get that you want to avoid mutexes but if you expect the code to grow (And more importantly, you expect not to be the only one working on it) things such as those are a good way to avoid throwing hands with the compiler
Pavel
Igor🇺🇦
Pavel
You can watch this talk about lock free programming. https://youtu.be/ZQFzMfHIxng
Yes, that's a great talk, but atomics just have the same issue as too many mutexes. I'm trying to layer my data in a way that it can be processed most efficiently (both for cache and branch prediction), if every variable in my app will be atomic then that will make all that effort meaningless.
I want to avoid the case when both atomics and mutex are needed (it won't be possible everywhere of course, but at least in most of the data)
Pavel
In any way, I already got a lot of helpful input. I'll investigate the links and think about what you've said
Thank you all ❤
Aakash
Pavel
*transactional mem!
At first started googling "transactional meme" :)
Thanks, will investigate as well
Aakash
Elisson
I've read the rules and I agree with them
Diego
Click the button my man
Lava
Sandro
I started using Qt Creator, is there an option to save the previous session code line in the Editor like VS Code does? Every time I need to remember where I stop last time...
Pavel
Sandro
Bumpy
anyone know what is the problem?
Bumpy
i want to split a given string
Bumpy
void stringSplit(char *string) {
char *runner = string + 0;
int counter = 0;
while (*runner) {
int current = 0;
while (*runner != ' ') {
counter ++;
runner++;
current ++;
}
char *word = (char*)calloc(counter + 1,sizeof(char));
char *start = string + counter - current , *end = string + counter;
while (*start != *end) {
*word = *start;
word ++; start++;
}
word[counter + 1] = 0;
printf("%s",word);
free(word);
runner ++;
}
}
Pavel
Bumpy
i know that its terrible
Pavel
Pavel
I think it can be done simpler if you just remember word start and calculate word end. And use them consistently, now it does some strange math that is hard to follow
MRT
how i can hold multidimensional array like int[10][20][30] to heap ? can anyone give me a example
MRT
Bumpy
char stringSplit(char *string) {
char *start = string;
char *end = string + lengthOf(string);
char *runner = string;
int len = 1;
while(*runner) {
if (*runner == ' ') len ++ ;runner ++;
}
char **words = (char)(calloc(len,sizeof(char*)));
int counter = 0;
int i = 0;
while (*start) {
int current = 0;
while (*start != ' ') {
counter ++;
current ++;
start ++;
}
if (current != 0) {
start = string + (counter - current);
end = string + counter;
words[i ++] = (char*)(calloc(current,sizeof(char)));
while (*start != *end) {
}
}
}
printf("%d",len);
}
Bumpy
i want to split the string into an array of char pointers
Bumpy
in the beginning im trying to count the number of words in vairable (len)
Bumpy
after that im allocate dynamically number of "strings" as number as len
Bumpy
current is allways count and if i want to the start sub string i doing counter - current
Bumpy
know how i can copy the chars in the inner while loop?
Pavel
AHMED
#include<iostream>
using namespace std;
int main()
{
constexpr auto mylambda = [](int x, int y) { return x + y; };
static_assert(mylambda(10, 20) == 30, "The lambda condition is not true.");
}
AHMED
What is the problem in the above code?
Vlad
Vlad
Could you give an error that compiler gives or smth
Vlad
How are we supposed to know?
AHMED
<stdin>:9:16: error: static_assert expression is not an integral constant expression
static_assert(mylambda(10, 20) == 30, "The lambda condition is not true.");
^~~~~~~~~~~~~~~~~~~~~~
<stdin>:9:16: note: non-constexpr function 'operator()' cannot be used in a constant expression
<stdin>:7:28: note: declared here
constexpr auto mylambda = [](int x, int y) { return x + y; };
^
1 error generated.
Vlad
Do you have c++17 standard enabled?
AHMED
I am using cxxdroid on mobile
Vlad
Bumpy
I tried to simplify the code more.
Bumpy
But the first word doesn't print.
Bumpy
"grabish value"
is
a
test
using
split
Pavel
AHMED