Anonymous
Does any of you program either in Java and c++?
Alpha Max
Hi
olli
Well, it can be theoretically because of branch prediction
There was pretty good paper "Sorting in the presence of branch prediction and caches" about that
Alpha Max
Ollli
Dima
lol
Alpha Max
😂
Pavel
I would expect potential cache misses to have a bigger impact, and that's where selection sort is really bad.
Not sure but I thought selection sort fetches data sequentially in a predictable manner, as it scans for the next smallest element 🤔
Iakovos
After all this I have one more question, should a descending array like this 5,4,3,2,1 be faster than a random one 3,5,2,4,1? Imagine this with large arrays
Iakovos
Again using selection sort
Iakovos
So it has to do with lower level stuff, right?
Iakovos
Caching, branch prediction etc
olli
So it has to do with lower level stuff, right?
why do you expect a difference for a sorted array? How is selectin sort optimized for this?
Alex
So it has to do with lower level stuff, right?
initially you should do profiling, and define what lines of your code are actually slow, and then find the reason
Alex
why do you expect a difference for a sorted array? How is selectin sort optimized for this?
we should not swap values for sorted array, theoretically it can be faster
Iakovos
When an array is already sorted then the comparisons still be made but not the swaps
Iakovos
So it does take time as well
olli
we should not swap values for sorted array, theoretically it can be faster
I know, but this would require you to add another branch
su
this is pointless speech, after all
Prometheus
Hey. Anyone have tips on storing a very large number of strings without running into address boundary errors?
Prometheus
I'm looking at numbers like 10,000 plus. Compiles fine but keep getting SIGSEGVed
Prometheus
What error do you get?
Prometheus
Does std::vector<std::string> not work?
Nope. That was what I tried originally. Then I tried an array. Then I tried just reading the lines from the file one by one and only storing the word I was going to use. That doesn't work either. The error is pretty short:
Prometheus
Program received signal SIGSEGV, Segmentation fault. std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator= (this=0x0, __str="-6426") at /usr/src/contrib/llvm-project/libcxx/include/string:2357 2357 if (!__is_long()) {
Prometheus
Yeah, no problem. Give me one second to toss it on pastebin
Prometheus
10k strings of length 1G will ruin any system
Thought it may work but I'm just trying to pick out a couple words at a time from the text file.
Prometheus
https://pastebin.com/5TsvXHN7
su
Thought it may work but I'm just trying to pick out a couple words at a time from the text file.
on windows, i prefer use MMF, on linux there similar apprach you can map your file handle into address space of a process without actually loading this dump in memory
su
replace ** with *
Prometheus
on windows, i prefer use MMF, on linux there similar apprach you can map your file handle into address space of a process without actually loading this dump in memory
I thought about using a map but it's a lot of work for something that would be run so rarely. Maybe I'll just shorten the list more.
su
have you ever read warnings messages? if no, here you are
Prometheus
Maybe I'll try running it on something other than my x220. Could just be how old my computer is.
olli
Maybe I'll try running it on something other than my x220. Could just be how old my computer is.
It shouldn't matter tho, how big is the file? this one? https://github.com/first20hours/google-10000-english
Prometheus
It shouldn't matter tho, how big is the file? this one? https://github.com/first20hours/google-10000-english
Yeah, it's that one. I didn't think it mattered much but while I was searching online for a solution before asking here I read that older hardware may not be able to handle that amount.
olli
Yeah, it's that one. I didn't think it mattered much but while I was searching online for a solution before asking here I read that older hardware may not be able to handle that amount.
it segfaults if it fails to open the file.. names is empty but you access the first element rand_num = rand() % num_lines + 1; p_word = names[rand_num]; ^^^^^^^^^^^^^^^
Prometheus
lots of work? seriously?
Not really. Never used them before lol
Alex
Not really. Never used them before lol
just open file, and call mmap
Prometheus
yes, but names can be empty
If it can't read the file but wouldn't that be caught with the if statement early on?
olli
If it can't read the file but wouldn't that be caught with the if statement early on?
it is, but you don't return? (even then, what if the file is empty?)
Prometheus
it is, but you don't return? (even then, what if the file is empty?)
Good point. I just never got the output from the error message. So I assume it has the file open.
Prometheus
just open file, and call mmap
Ok, I'll look into it. Thank you. Wouldn't hurt to learn something new.
Prometheus
just open file, and call mmap
Just a quick question. If I understand correctly, from what I’ve read, once the file is mmapped it can be accessed just like any other file?
su
Just a quick question. If I understand correctly, from what I’ve read, once the file is mmapped it can be accessed just like any other file?
it is a pointer, which can be advaces, but not points to conventional memory but a pointer scraping the hard disk surface while reading bits, all the magic is done by OS kernel
su
that is why mmf usually reads files in blocks of fixed size, cause it is mapped to block devices, like HDD
su
it is up to you to implement buffering etc, block read function, and go until the end, at least in windows api
su
like until not error/end read block process block advance block count/pointer to the next position
su
the main difference is that you do not keep all data in memory, read file byte after byte using your buffer
Alex
that is why mmf usually reads files in blocks of fixed size, cause it is mapped to block devices, like HDD
in linux you can access byte by byte just like for regular pointer. but I am not aware about limitations for huge files
su
very cool !
Alex
Just a quick question. If I understand correctly, from what I’ve read, once the file is mmapped it can be accessed just like any other file?
why do you map if you want access it as regular? treat as array of bytes(readonly is enough for you as I understand)
su
or @NoFearFreedomsHere can use buffering technique and read in blocks
Alex
Map was suggested to me.
just mmap file and you already have byte array with your strings
Prometheus
Lol I should’ve stuck with pulling them in line by line into a vector
Alex
do you need lines? just find all \n and save them in array of pointers
Георгий
/report
Tangent Alpha
lemme see
Tangent Alpha
oh good what was wrong?
Prometheus
do you need lines? just find all \n and save them in array of pointers
I did that. That’s how I got the error. Also tried saving the lines in a vector but I keep getting out of bounds errors
Prometheus
Why are to using global variables?
su
https://repl.it/@ArturMustafin/c-random-string
su
oh good what was wrong?
he had local variable with the same name as global variable and *** where not aplicabe. see ^ fixed version
Prometheus
it is, but you don't return? (even then, what if the file is empty?)
You we're right. I did some more digging and for whatever reason the program will not read the file. Not sure why but it isn't an issue with the size of the file.
Don Peter Joseph
https://pastebin.com/2MZKDeyY
Don Peter Joseph
quick sort code. can anyone suggest where i have gone wrong?
Hadaward 'Solly'
that's not really a C question, but look up binary decision diagrams