« first day (538 days earlier)      last day (4408 days later) » 

11:00 PM
@Abyx we have boost::optional
 
How is it not?
 
@ScottW they're very similar
 
@MooingDuck Perhaps. I'm sure someone can come up with something with a better name
 
in·fre·quent
adj.
1. Not occurring regularly; occasional or rare
Aaand we go full circle.
 
@daknok_t but not std::optional
 
11:01 PM
@Insilico mutable_non_owning_reference_thing
 
@ScottW: Eh? "Barely happening" == "it does happen, just not often"
 
@CatPlusPlus Aaaand, English class dismissed.
@ScottW I don't know. Honest guy.
 
@MooingDuck: Let's not paint the bike shed. :-)
 
@Abyx I don't think that will take a long time.
 
@daknok_t 10 years
 
11:02 PM
I don't really care, for me they're interchangeable.
 
That's less than my age, so it's fine.
 
So "occasionallly" means something that happens more often than "barely happening"?
That's kind of what I'm sensing fron a connotation standpoint
 
But anyway, there is no reason not to use the boost header-only libraries when they provide what you need.
brb
 
@daknok_t there are some reasons, IRL. (like stupid cow-workers)
 
@Abyx rename "boost" to whatever namespace you are using, and they won't find out. :P
 
11:08 PM
namespace my_awesome_library = boost;
 
posted on April 06, 2012 by Herb Sutter

Nicely put: Most companies (including web startups), he said, are looking to “wow” with their products, when in reality what they should be looking for is an “‘of course’ reaction from their users.” Simple and obvious beats flashy. So many great designs are obvious in retrospect. Hat tip to John Gruber. Filed under: Friday Thoughts

 
"Posted 10 messages in chat that were starred by 10 different users."
I don't remember posting 10 starred messages
 
@Insilico but chat does.
 
Can I ask Chat what those starred messages are?
 
11:14 PM
@MooingDuck: Too bad I can't run an SQL query on the 158 pages of starred messages
 
@Insilico 3 of them are on the first two pages, but yeah
@Insilico data.stackexchange.com found it
 
@MooingDuck: Are chat transcripts part of the data dump?
 
@Insilico I haven't the foggiest idea
 
Hello
 
Hi
 
11:18 PM
Hello @newprogrammer
 
When you open a file with iostream, does the file go into the computer's RAM?
 
@newprogrammer partially, sometimes
 
fstream, you mean.
 
ya that's what i mean
like when i do >> to read a line from it
 
@newprogrammer: That's dependent on how the operating system handles it
 
11:19 PM
the OS just gets the line from the file
 
You don't use >> to read a line, you use getline.
 
For small files the OS might just load the entire thing in memory
 
@newprogrammer usually it will load a "page" (~4096 bytes) or so at a time
 
well ya
oh ok
 
@newprogrammer usually. sometimes. maybe.
 
11:20 PM
oh mooing duck really?
i did not know that
 
@newprogrammer: Of course there's no guarantee that's how the OS works
 
that's probably how windows, os x, and linux do it right?
 
@newprogrammer: Probably
 
@newprogrammer it changes, depending what the computer is doing (besides your program), and how you open the file
 
there is more than one way to open a file?
 
11:21 PM
@newprogrammer sure, there's a buffering option somewhere
 
@newprogrammer: Oh yes.
At least on Windows there's tons of options wrt opening files
 
@Insilico I think he means with fstreams
 
Some information about how Windows caches files
 
i thought, if you wanted to write code that works with files portably
you should just use fstream
instead of using windows stuff
 
@newprogrammer yes
 
11:23 PM
and fstream just has .open() right?
 
@newprogrammer: Yes.
 
but if you call sync_with_stdio on the stream, it may remove some application buffering (may or may not affect OS buffering)
 
fstream has options for opening the file
 
where would i put sync_with_stdio
 
You can also open the file directly using the constructor of fstream, without calling .open(...).
 
11:24 PM
 fstream myfile("thing.txt");
 myfile.sync_with_stdio();
 
@newprogrammer: You need to remove buffering?
 
filestr.open ("test.txt", fstream::in | fstream::out | fstream::app);
!!!
what are those fstream::in things
 
@newprogrammer don't use in and out at the same time, it's too easy to make mistakes
@newprogrammer those tell it how you want it to open the file
@newprogrammer there it's being opened for input, output, and in append mode.
 
but what if you want to read and write to a file
 
@newprogrammer read it all, modify in memory, write it all.
@newprogrammer it can be done at the same time, but it's super dangerous, and almost nobody does it right.
 
11:26 PM
Using mmap, right?
 
mmap = memory mapping?
 
@daknok_t no, I mean with iostreams
@newprogrammer yes
 
Ah k.
 
why would it be less dangerous to do it in memory
isnt it just the same thing
same logic and stuff
 
@newprogrammer because then you're using the memory as a buffer, avoiding the problem
 
11:27 PM
which problem
 
@newprogrammer: Presumably, the data would be stored in some sensible working form when you've loaded it into your program
 
fstream myfile("names.txt");
char first;
myfile << first;
myfile >> "HI";
myfile << first;
 
A file is just a collection of bytes
 
now what is the value of first? (I HAVE NO IDEA!) It might be the second letter in the file. Or it might be an I. I dunno. and that is the problem.
 
uhh give me a minute to think about that
 
11:29 PM
It's way easier to work with data stored in the proper data structures in your program than trying to modify the bytes in a file directly
 
@insilcio, but it takes work to convert those bytes into a data structure no?
 
@MooingDuck first is simply an uninitialized variable, and the code won't compile, because you can't read into a string constant.
 
@newprogrammer not really. You can just read into a buffer, or mmap
 
@newprogrammer: Yes, but data structures are easier to work with than with raw bytes
 
Opening for reading and writing is not a real problem though -- I've done it for databases of various sorts many times, without any real difficulty at all.
 
11:30 PM
ya mooing duck, did you get the >> and << 's backwards
or am i just reading your code wrong
 
@newprogrammer yes I did :(
 
oh ok
 
Okay why is it that the PHP and JavaScript rooms have the most flagged messages?
Or is it my selection bias (most likely the latter)
 
well mooing duck
isn't there like
uhh
 
@Insilico my tiny sample size agrees.
@newprogrammer just read it into a buffer :) or mmap.
 
11:32 PM
The single biggest difficulty is that you have to ensure against doing a read followed immediately by a write (or vice versa). You have to do a seek or flush in between. For a database that's rarely a problem though -- you're doing it specifically to seek directly to a record, and read or write as appropriate.
 
Oh and if use use mmap, use it with RAII.
 
i probably won't be using mmap
it's more like updating a record in a database
(mmap is less useful to that end right?)
Do you suffer hard disk latency every time you read or write to the disk
 
@newprogrammer It should work all right for it. Its biggest shortcoming is difficulty when/if you want to deal with a file that's larger than available address space (unlikely to be a problem on a 64-bit system though).
 
@newprogrammer: Not really.
 
or can the OS kind of do multiple read/writes in one go
 
11:36 PM
Pretty much all non-stupid OSes will cache reads and writes
 
oh ok
 
That being said you're better off reading/writing big chunks
 
that does make sense
 
So you don't suffer from too many context switches
 
uhh by that, do you mean, the write and read calls to the OS themselves are expensive?
or am i misinterpreting your statement
 
11:38 PM
@newprogrammer Yes, usually, though for database-style updates, it may not do a lot of good (when you're reading/writing random locations, it's hard for it to help a lot). This kind of loads is where people really find SSDs helpful.
 
@newprogrammer: Yes.
Calls to the OS are much more expensive than calls to functions within your program
 
hmm isee
i see*
but i thought it's kind of hard to avoid calls to the OS
 
Unless the function was implemented in userland
 
for example, doesn't the "new" operator make a call to the OS to request memory from the heap?
 
@newprogrammer: Not always
 
11:40 PM
@newprogrammer very rarely
 
@newprogrammer It's easy to avoid them -- as long as you don't want to do anything useful!
 
The runtime library might amortize the cost by allocating a big chunk of memory in advance
Then give out the pieces as needed when you ask for it
 
Then why do some people do things like "memory pooling"
 
runtime libraries tend to cache the file IO as well, to avoid OS calls
 
@Insilico Where "might" means "always will" except with a minuscule number of truly braindead heap managers.
 
11:41 PM
@newprogrammer because custom allocators can beat the general allocator for certain situations
 
@newprogrammer: Because memory allocation is slow as shit in C++
 
even if there are no calls to the OS?
 
@newprogrammer the heap is very complicated
 
@MooingDuck s/is/can be/
 
Think about it, the runtime has to be able to satisfy requests for memory of arbitrary sizes at arbitrary times with arbitrary lifetimes
 
11:42 PM
@JerryCoffin yes well. You can make simple heaps, but they tend to be a lot slower for the general case.
 
@Insilico s/is/can be/ seems to apply here too.
 
@Insilico and then recombine them later. That's the hard part.
 
And for that reason, it can be very tricky to optimize programs that are allocation intensive...
 
where is the implemenation for the allocator?
the C runtime library?
 
@newprogrammer yup
 
11:42 PM
@newprogrammer: Yes.
 
and this is different per platform right?
 
@newprogrammer yes
 
Yes, although implementations are definitely different
 
I see
 
There is no general purpose allocator that works fast in every single situation
 
11:44 PM
then how does java do it
 
There will be certain patterns of memory allocation that cause the allocator to work very slowly
@newprogrammer: Java moves memory around so that the heap stays compact
 
and c++ doesn't?
 
And when you allocate memory it simply gets the next available space
C++ does not move memory around
 
why not
will pointers point to the wrong place or something
 
Moving memory around is way more complicated than you think it is
 
11:46 PM
@newprogrammer it can't, because it decided it wants to be fast at everything else instead
 
Way too difficult with pointers
 
@newprogrammer No -- C++ doesn't allow it.
 
@newprogrammer yes
 
That's how Java deal with memory of arbitrary sizes at arbitrary times with arbitrary lifetimes being allocated
The drawback is that the GC has to run the MoveMemoryAround() routine sometime
 
so what price does java pay
for doing that
 
11:47 PM
@newprogrammer everything else goes slower
 
@newprogrammer The main problem is that it requires you to be able to identify pointers, so when you move something you can update all the pointers to the new address. That pretty much requires that the compiler emit something (usually some extra data) to be able to identify pointers.
 
@newprogrammer: The price is that some of the program time will be spent running the MoveMemoryAround() routine
 
uhh does it just call movememoryaround() randomly or what
 
(of course the function isn't actually called MoveMemoryAround(), it's just a name)
 
@newprogrammer yes it does
 
11:48 PM
@newprogrammer: Yes, but you still have to run it
 
that does not sound very predictable
 
@newprogrammer it also has a GC thread that runs randomly in teh background
 
A function isn't very useful if you don't use it
 
@newprogrammer it isn't.
 
@newprogrammer Contrary to popular belief, the price isn't necessarily running slower -- it's primarily needing a lot more memory available to run as fast (figure 7x as a rule of thumb).
 
11:49 PM
Of course the speed vs. memory tradeoff is quite common in programming (you run into them often)
 
if memory gets moved around so much
how do variables know where the data is
 
@newprogrammer: The references are modified to reflect the new positions
 
@newprogrammer the movememoryaround() has to update all the pointers to the memory it moves.
 
@newprogrammer That's what I was talking about earlier: when the object gets moved, all pointers to it have to be updated.
 
oh ok
but C++ doesn't do that
 
11:50 PM
@newprogrammer nope
 
But the real problem is that the GC/allocator/memory manager/whatever doesn't know how you will use the memory
Only you (the programmer) knows that
 
You mostly don't need to use pointers directly anyway in C++.
 
There is an alternative called an object table, where the pointer in your program actually points to another pointer in the object table. When the object gets moved, only the pointer in the object table needs to be updated. That means double indirection though, which has its own penalty (GC runs a little faster, but everything else a bit slower).
 
What is the cost of indirection
compared to like
 
@daknok_t True, but you avoid them primarily by using objects that handle them internally (string, vector, etc.)
 
11:52 PM
5+5
is it the same?
 
@newprogrammer: No, it's definitely not the same
 
much higher?
 
I don't know about "much" higher
But it's definitely higher
 
@Jerry Coffin that's why I said "directly" (:
 
@newprogrammer Depends heavily on caching. If it has to retrieve a pointer from memory, figure 50x slower. If the pointer is in cache, figure 5x slower.
 
11:53 PM
@newprogrammer usually it's higher, but how much varies a lot
@newprogrammer if it's been paged, take a nap
 
The term memory hierarchy is used in computer architecture when discussing performance issues in computer architectural design, algorithm predictions, and the lower level programming constructs such as involving locality of reference. A 'memory hierarchy' in computer storage distinguishes each level in the 'hierarchy' by response time. Since response time, complexity, and capacity are related, the levels may also be distinguished by the controlling technology. The many trade-offs in designing for high performance will include the structure of the memory hierarchy, i.e. the size and te...
 
@MooingDuck Yes, quite true.
 
i see
 
The processor registers are the fastest (access time in nanoseconds)
 
i thought there was more than one cache
 
11:54 PM
The disk is the slowest (access time in milliseconds - seconds)
@newprogrammer: Yes, there's more than one cache
So?
 
@newprogrammer There;s usually 3 (right now)
 
0
A: c++ new and delete

Cheers and hth. - AlfUse std::string and be done with it. Just in case it is not obvious, that will take care of the problem. But also, to avoid some similar problems and to just understand a bit more of the issues involved, do look up the rule of 3, or as it's now known with C++11, the rule of 5.

^ Sometimes one does not need to know exact problem, in order to identify a cure
2
 
@CatPlusPlus: have you ever tried combining glload and oglplus? I can't seem to get the latter work without glew.
 
@newprogrammer There usually is -- typically at least two levels of cache in the processor, and at level 1, there are usually separate caches for code and data.
 
The hard disk is at least 1000000x slower than RAM and the cache(s) (ballpark estimate)
 
11:56 PM
And SSD is similar, but faster.
 
I have not been able to get glload to work with anything except the other things that it comes with
dang 1000000x slower
 
@newprogrammer I actually haven't had any problems with it, but it seems that oglplus relies on some built-in GLEW constants, which is nasty
 

« first day (538 days earlier)      last day (4408 days later) »