Ammar
Hey Ajay, take a look to std::fill_n. It is probably what are you looking for.
Ajay
Ajay
I often get segmentation fault in my cpp code, debugging is a way but are there any other ways to tackle with this problem or ways that can help to find at which line did the exception occurred?
Ammar
Ammar
Valgrind should also be helpful, it also tracks invalid read/write and memory leaks.
noop
Dima
Ammar
Best tools for debugging: gdb, valgrind, radare2
Ammar
Also use gef for your gdb. It makes you easier to see instruction, registers and stack.
Mar!o
Mar!o
my classic was:
void free_stuff(stuff **restrict const stuff) {
free(stuff); <— should be *stuff
*stuff = NULL;
}
Anonymous
I'm running a function on a thread, and it contains a gets that asks for input.
Now, after starting this thread, I decide that I don't need the input anymore.
Is there any way I can "close" the gets prompt? Like supplying it with some random data?
Ammar
Ammar
I am unsure btw
Anonymous
That's the problem. It cannot wait.
I won't know if the input comes first, or the decision that I don't need the input does.
Ammar
Just thought that it was Linux.
Ammar
I wonder what is the purpose of that folder.
Ammar
I see, thanks.
Ammar
Try this one btw https://stackoverflow.com/questions/38329044/closing-then-opening-standard-input-in-c-under-linux
Anonymous
Well, I'm trying to run a chat server, that constantly asks for user input, and prints a message immediately when it's received.
The receiver function also runs on a thread.
I'll try to think of some other way then.
Ammar
I haven't tried but this eww https://serverfault.com/questions/188936/writing-to-stdin-of-background-process
Ammar
Ajay
Yes, sure.
it kinda stops there and does nothing
Ajay
like this, IDK why it isn't outputting anything.
Ammar
Ok, I agree with you.
Ammar
Ammar
Try to send SIGINT and check the current instruction.
Ammar
CTRL + C
x/10i $rip
Ammar
I assume the arch is x86_64
Ludovic 'Archivist'
It is the same amount of skipped items for any hash, it is an increasingly large amount until you have failed more than 3000 probings and then it flips back to linear probing
Ajay
it is simple hello world, I was just trying it for my previous code but it kinda started waiting, so I wrote a simple hello world to check if it still waits and see it still is waiting. IDK why?
Anonymous
If you want the details, the receiving function stops as soon as the connected socket is closed. This is the point when I want the gets of the sending function to be closed too.
It does stop when it fails to send whatever input you give, but that's one useless input I'm trying to get rid of.
Ludovic 'Archivist'
Your thing reminds me of cuckoo hashing, which I did use at some point
Ludovic 'Archivist'
You can find an implementation of this here (albeit not for a hashmap but a quotient filter): https://git.nekoit.xyz/Archivist/gplib/src/branch/master/include/gp/quotient_filter.hpp
Ajay
Anonymous
Anonymous
Reminder that compilers special case functions like memset so sometimes they may not work
Ajay
yeah it shows the correct code
Actually, I'm using MacOS mojave and so when i sought the problem online, i followed this link which says gdb is not compativle with MacOS sierra(didn't check for mojave)
Ammar
Ajay
Ajay
aah man, earlier I was doing ctrl+z which was working(stopped the running program) because ctrl+c wasn't but now even ctrl+z isn't working.
Ammar
Ajay
Ammar
Try valgrind sir.
Sasuke
My program uses SDL library which is cross platform but installation is needed for every platform which is different accordingly so I wanted to ship my program without hassle to the user like installing a compiler and installing required libraries how can I do that?
Ammar
Ajay
Try to run a segfault code then
yes, It is showing
Invalid write of size 4
==6760== at 0x100000DA9: solve() (ga.cpp:11)
==6760== by 0x100000DC2: main (ga.cpp:17)
Ammar
Good, happy to work.
Ajay
But, when I simply create int a[3000000]; inside main and run then why doesn't that give segmentation fault? But, it does give segfault in that code. Any reason?
Ajay
Ajay
I tried experimenting doing long long a[3000000000000000000000]; then the compiler says error: size of array 'a' is negative, why? Even adding ll at the end of that number says that too.
Ajay
long long is ~ 1e18, so i think that shouldn't be the problem
Ammar
Anonymous
The largest array I've ever seen was like 3000 in size
Ajay
oh, didn't see that 😅
Anonymous
Where? In Linux kernel COMMAND_LINE_SIZE constant
Ludovic 'Archivist'
Anonymous
Anonymous
Or his numbers
Ammar
Ludovic 'Archivist'
Still nowhere close to 3e21
Yeah, I think the largest array I ever used was like, 16'000'000 elements or so
Ammar
https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/setup.h#L7
Anonymous
Anonymous
It was an android kernel
Anonymous
Besides if you've ever seen an android kernel cmdline it's way bigger than 255 chars
Anonymous
Ammar