Aakash
I'm not trying anything. I just pointed that your code is too slow
It’s not my code! I used her code with clock(); that’s it! And modified to see primes with (if).. you may check again🙃
Sandro
Hello everyone, I have a little issue with regular expression, my intend is to have a full control of keyboard input in a field of form with ncurses. I need to impose the user input a valid phone number string, right now I have build this parameters "^\\+?[0-9]+ " Now the user can input a number with or without + at begin of string, and it's mandatory to input at least a digit, eg.: +3933525773 or 57437848648 Any alphabetical character it's forbidden, or to input + character in a different position to the begin of the string. But now my intention to improve the code is to add the possibility to have also # and * characters in the string wherever, for example: 335123#5*57 or +3935*#122#5663* And so on... Can someone help me please?
Aakash
well, I copied the code you posted - why repost code?!
You need to understand the code first; she is “iterating” variable “rax”; ..she’s counting “rax” values ; and seeking time limit. What time-limit I don’t know!! That’s why I played the whole program. Hope you get this time😄
olli
It’s all because of iteration rax++
well, yes and no. The bounds are chosen poorly
Aakash
well, yes and no. The bounds are chosen poorly
👍😄 I suggest you write a simple program thats does it’s faster than hers on same high prime number & submit it here!! Let everyone knows about your code.
Roy
Hi, it's correct code? // can i correct hash .c_str() ptr data or its UB? make_hash(std::string{"Hello"}.c_str());
Crow
xd
Dima
lol
Crow
i just put a pastebin link
Crow
😢
Dima
Yeah I see
Dima
Try to post it with spaces ¯\_(ツ)_/¯
Dima
we need to set this bot up right
Crow
hacking the bot
Igor🇺🇦
Hi, it's correct code? // can i correct hash .c_str() ptr data or its UB? make_hash(std::string{"Hello"}.c_str());
It's not UB behaviour, but every string object will return different char*, even if strings are the same.
Igor🇺🇦
Example?
What example do you want?
Roy
What example do you want?
i mean, what different? null terminator between different compiler?
Igor🇺🇦
i mean, what different? null terminator between different compiler?
No. It's not related to compilers. c_str returns pointer to internal string buffer. Every object has its own. So you'll get different results.
Stars✨
/getfreeprogrammingbook
Igor🇺🇦
Doesn't the standard stipulate that c_str () must contain a null terminator?
I never said it will not contain it. The value of const char* will be different.
Igor🇺🇦
string(".").c_str() != string(".").c_str()
Igor🇺🇦
strcmp, anyone?
I don't understand why would @r_mustang want to calculate hash of c_str in the first place. There is no need in strcmp when we have string class.
MLDA
How I give length for variable 🤔
✨ Anatolii
I don't understand why would @r_mustang want to calculate hash of c_str in the first place. There is no need in strcmp when we have string class.
блин, так прикольно, когда несколько русских людей пытаются что-то писать на английском
Антон
блин, так прикольно, когда несколько русских людей пытаются что-то писать на английском
Still не так смешно as Russian человек mixing French with Undercitian английский with русский
Roy
I don't understand why would @r_mustang want to calculate hash of c_str in the first place. There is no need in strcmp when we have string class.
Im generate FNV hash from protocol, ip, port and use them for search in vector, it's faster than constantly comparing 3 variables with each other in find_if
我是大娃
why pthread_spin_lock is almost 10 times faster than my implement
我是大娃
#include "../util/Timer.hpp" #include <atomic> #include <functional> #include <iostream> #include <thread> #include <pthread.h> using namespace std; class SpinLock { public: SpinLock () { _flag.store(false); } bool TryLock() { bool expect = false; return _flag.compare_exchange_weak(expect, true); } void Lock() { bool expect = false; while(!_flag.compare_exchange_weak(expect, true)) expect = false; } void UnLock() { _flag.store(false); } private: atomic<bool> _flag; }; pthread_spinlock_t g_lock = 0; void func(int &arg, int total) { while(total-- > 0) { pthread_spin_lock(&g_lock); ++arg; pthread_spin_unlock(&g_lock); } } SpinLock g_lock2; void func2(int &arg, int total) { while(total-- > 0) { g_lock2.Lock(); ++arg; g_lock2.UnLock(); } } const int kAddNum = 1000000; const int kRoundNum = 100; int main() { pthread_spin_init(&g_lock, PTHREAD_PROCESS_PRIVATE); Timer t; t.TimerBeg(); for(int i = 0; i < kRoundNum; i++) { int value = 0; thread a(func, ref(value), kAddNum); thread b(func, ref(value), kAddNum); a.join(); b.join(); } t.TimerEnd(); cout << t << endl; t.TimerBeg(); for(int i = 0; i < kRoundNum; i++) { int value2 = 0; thread c(func2, ref(value2), kAddNum); thread d(func2, ref(value2), kAddNum); c.join(); d.join(); } t.TimerEnd(); cout << t << endl; return 0; }
Sandro
^\+(?:[0-9]●?){6,14}[0-9]$
Thank you Andrew I will try it and I will let you know👍
Igor🇺🇦
#include "../util/Timer.hpp" #include <atomic> #include <functional> #include <iostream> #include <thread> #include <pthread.h> using namespace std; class SpinLock { public: SpinLock () { _flag.store(false); } bool TryLock() { bool expect = false; return _flag.compare_exchange_weak(expect, true); } void Lock() { bool expect = false; while(!_flag.compare_exchange_weak(expect, true)) expect = false; } void UnLock() { _flag.store(false); } private: atomic<bool> _flag; }; pthread_spinlock_t g_lock = 0; void func(int &arg, int total) { while(total-- > 0) { pthread_spin_lock(&g_lock); ++arg; pthread_spin_unlock(&g_lock); } } SpinLock g_lock2; void func2(int &arg, int total) { while(total-- > 0) { g_lock2.Lock(); ++arg; g_lock2.UnLock(); } } const int kAddNum = 1000000; const int kRoundNum = 100; int main() { pthread_spin_init(&g_lock, PTHREAD_PROCESS_PRIVATE); Timer t; t.TimerBeg(); for(int i = 0; i < kRoundNum; i++) { int value = 0; thread a(func, ref(value), kAddNum); thread b(func, ref(value), kAddNum); a.join(); b.join(); } t.TimerEnd(); cout << t << endl; t.TimerBeg(); for(int i = 0; i < kRoundNum; i++) { int value2 = 0; thread c(func2, ref(value2), kAddNum); thread d(func2, ref(value2), kAddNum); c.join(); d.join(); } t.TimerEnd(); cout << t << endl; return 0; }
atomic<bool> is not very well suited for this. Try something like class SpinLock { std::atomic_flag locked = ATOMIC_FLAG_INIT ; public: void lock() { while (locked.test_and_set(std::memory_order_acquire)) {;} } void unlock() { locked.clear(std::memory_order_release); } };
Igor🇺🇦
Use https://en.cppreference.com/w/cpp/atomic/atomic_flag. That's what it is there for
olli
why pthread_spin_lock is almost 10 times faster than my implement
looking at the implementation of pthread_spin_lock could give some hints, there are actually a lot of comments in there. E.g. they add a nop (pause on x86/64) which boosts the performance in spin locks. From the Intel SDM (8.10.6.1, Jan19) Intel recommends that a PAUSE instruction be placed in all spin-wait loops that run on Intel processors supporting Intel Hyper-Threading Technology and multi-core processors. From the AMD Manual, Vol 3 (P270, Rev 3.31) Improves the performance of spin loops, by providing a hint to the processor that the current code is in a spin loop. The processor may use this to optimize power consumption while in the spin loop.
我是大娃
Thank you
Pavel
how can I allocate huge VLA in heap?
Pavel
by "huge" I mean 10-dimensional
MᏫᎻᎯᎷᎷᎬᎠ
@ollirz Is there any framework you'd love to work with, alternative to Qt
olli
how can I allocate huge VLA in heap?
The best option would probably be to compute the required space and allocate it on the heap. Then have a helper function that converts your index into an offset into the flat buffer. Are you sure using a 10-dimensional array is your best choice?
olli
@ollirz Is there any framework you'd love to work with, alternative to Qt
It always depends on what you want to do. When it comes to UI in C++, I still think Qt is your best shot and don't see it changing anytime soon. Otherwise Poco is a really nice set of libraries and of course boost and Abseil-Cpp.
Anonymous
Hey guys I'm a beginner at C++. Can you please suggest be an authentic youtube channel and a book for the same.
Anonymous
I need your help .
olli
There is Copperspice You heard of it?!
I have heard of it some time ago but I never used it. Wasn't the idea to have one set of libraries that basically can do everything? While the idea might be nice I always preferred libraries that are really great at what they want to do and not good at everything.
MᏫᎻᎯᎷᎷᎬᎠ
I have heard of it some time ago but I never used it. Wasn't the idea to have one set of libraries that basically can do everything? While the idea might be nice I always preferred libraries that are really great at what they want to do and not good at everything.
Yeah, CopperSpice tries to replace Qt by removing moc and depends on purely C++ feature to implement some reflections to support signal/slot mechanism CopperSpice can be treated as a set of independent libraries, you can even use a single one without the other libraries and it's under development by some of the brightest minds in the C++ community like Jan Wilmans and Odin Holmes
Igor🇺🇦
how can I allocate huge VLA in heap?
What does it mean VLA on heap? The point of VLA in C is that it's allocated on stack. Just use pointer and malloc of you want to use variable size array
MᏫᎻᎯᎷᎷᎬᎠ
Yeah, CopperSpice tries to replace Qt by removing moc and depends on purely C++ feature to implement some reflections to support signal/slot mechanism CopperSpice can be treated as a set of independent libraries, you can even use a single one without the other libraries and it's under development by some of the brightest minds in the C++ community like Jan Wilmans and Odin Holmes
But Qt would move out moc also when reflections lands, which is probable in C++23, but I don't think Qt will remove it at that time since Qt 6 is freshly released and it requires C++17 compiler and major version of Qt are known it takes many years to update
olli
Yeah, CopperSpice tries to replace Qt by removing moc and depends on purely C++ feature to implement some reflections to support signal/slot mechanism CopperSpice can be treated as a set of independent libraries, you can even use a single one without the other libraries and it's under development by some of the brightest minds in the C++ community like Jan Wilmans and Odin Holmes
While these ideas sound great from a C++ perspective, I don't see a lot of people and especially companies caring too much about these parts. Qt has a big advantage since it's widely used and well known and there exists so much documentation and tooling around it.
MᏫᎻᎯᎷᎷᎬᎠ
While these ideas sound great from a C++ perspective, I don't see a lot of people and especially companies caring too much about these parts. Qt has a big advantage since it's widely used and well known and there exists so much documentation and tooling around it.
For tooling-plugin yeah The documentation CopperSpice has the offline documentation too, and nearly everything that Qt has, except for lack of support of some clases and android platform (which is planned for) Also it has a tool for converting Qt headers to the CopperSpice headers It was originally derived from Qt 4 so the code someone wrote wouldn't change so much
MᏫᎻᎯᎷᎷᎬᎠ
olli
It's planned to support Qml
Granted, the post is quite old but I haven't kept up with the project in a while From their forum I think there is definitely room for a QML-like-thing, but IMHO it probably won't be QML (because specific design and behavior changes would be necessary, IMHO). From
Mahim
Can we multiply a character by using a integer?
Igor🇺🇦
Can we multiply a character by using a integer?
you can, but what will the result represent? what does it mean when you multiply 'A' by 3 ?
olli
But I can see the Biggest advantage here(removing moc) would be pointless in the future since In their talk(The CopperSpice implementors) mentioned that Qt developers intends to remove moc but when the language support Reflections
But do you actually think CopperSpice can succeed? How are a handful of people supposed to hold of with a company and tons of partners. Additionally most people move their UI work to web based stacks or React native anyway...
MᏫᎻᎯᎷᎷᎬᎠ
But do you actually think CopperSpice can succeed? How are a handful of people supposed to hold of with a company and tons of partners. Additionally most people move their UI work to web based stacks or React native anyway...
tbh I'm not sure, unless some kinda big jump happened because CopperSpice will have to carry a lot in order to catch up with Qt like Design Sudio, popularity..etc + as mentioned above their main drive(removing MOC) will be pointless at some time in the future, since reflections will land and Qt company will maintain their framework nicely that time
olli
tbh I'm not sure, unless some kinda big jump happened because CopperSpice will have to carry a lot in order to catch up with Qt like Design Sudio, popularity..etc + as mentioned above their main drive(removing MOC) will be pointless at some time in the future, since reflections will land and Qt company will maintain their framework nicely that time
Based on the fact that they announced it 4+ years ago, I was barely able to find screenshots of a CopperSpice UI makes me feel the project is basically dead. Also, do that many people actually dislike moc? I would assume most people don't care, they want good tooling and a fast inner dev-loop.
MᏫᎻᎯᎷᎷᎬᎠ
They got a tool to show some prototype of what CopperSpice can do
MᏫᎻᎯᎷᎷᎬᎠ
it's called KitchenSink
Igor🇺🇦
Int x=5; Printf("*" * x) Is this working??
"x" is not char, it's char*. Big difference. It will compile, but will probably crash
Ammar
Int x=5; Printf("*" * x) Is this working??
"*" in that code will evaluate to const char * which is a memory address. It is probably valid a expression if you cast it to uintptr_t (I haven't tried, though).