« first day (443 days earlier)      last day (4488 days later) » 

Xeo
8:00 AM
Funny
My eyes are playing tricks on me!
 
Right.
You play tricks with the bottle, and your eyes play tricks with you.
 
Xeo
But I don't drink alcohol. :(
 
> I've never so confidently clicked "Not a real question". – Chris 2 mins ago
 
@RMartinhoFernandes There isn't even a question mark.
What the hell, there's a .NET 4.5 now?
 
Is that out already?
I thought that came with VS11.
It's the one with all the async stuff.
 
8:10 AM
Oh, that's the one with C#5.
 
But, it's just a developer preview as of now.
 
Well, I've checked the Standard for what constitutes a constant expression and what kind of non-type template parameters are allowed and I've come to the conclusion that I'm going to play video games.
2
 
And I think it won't ship Roslyn yet. Which is what I really really want to play with.
 
XD
 
8:11 AM
@LucDanton You had to look at the standard for that?
 
@EtiennedeMartel C++11 is playing with my heart :(
 
Xeo
@LucDanton If I had my xbox controller here, I'd do the same thing
 
@RMartinhoFernandes Yeah, that's going to be cool.
 
@EtiennedeMartel He was looking for a loophole to hack string literals into template arguments.
 
@LucDanton C++11 is playing with my eye sockets and I'm not sure I like it.
1
Q: Inner functions dealing with variables from the scope

wal-o-matI have a snippet of code like this: std::list<Point> left, right; // ... fill lists ... // now, calculate the angle between (right[0], right[1]) and (right[0], left[0]) double alpha = angle(*(right.begin()->get()), *(((++right.begin()))->get()), *(left.begin()->get()) ); std::co...

 
8:16 AM
@EtiennedeMartel Looks like he's using lists to emulate pairs.
 
He's probably done some Lisp before.
 
Xeo
> *(((++right.begin()))->get())
I wtf'd
 
"What what the the fuck fuck", said Day9.
Well, gentlemen, with that said, I'm going to get some sleep.
See ya everyone.
 
Xeo
Damn.
I just noticed my resource management system doesn't deal with alignment at all
 
Xeo
8:23 AM
It just increments a pointer into a buffer...
 
Or simply aligned_storage.
@Xeo No, alignas is something you put on a declaration.
It's not the std::align function I'm talking about.
 
Xeo
@RMartinhoFernandes I meant my alloc pools
 
You can say alignas(double) int x;
 
@RMartinhoFernandes Doesn't help if you want to store heteorgenous types into a single untyped buffer. have to do alignment manually then
 
@jalf aligned_union!
 
Xeo
8:25 AM
I basically have a char buffer of a certain size and just take the amount I need from there
 
does that exist?
anyway, that might give you unnecessary padding, and requires a bounded set of types. ;)
 
@jalf Yes. It's just not supported in GCC before 4.7, I think.
@jalf How do you make it work for an unbounded set of types without unnecessary padding?
 
@Xeo if you fill it up from the back, you can just mask out the lower bits of the current "next" pointer, according to the object's required alignment
 
Xeo
huh?
 
@RMartinhoFernandes determine the object's alignment, check if the current position in the buffer is suitably aligned, if not, add/subtract from the pointer to get an aligned address
 
8:27 AM
std::align then!
The standard has all those tricks!
 
@Xeo Say you want to store an object of size 24 which requires 8-byte alignment. Take the pointer that points to the beginning of the last object inserted, subtract 24, and then mask out the lower lg(8)==3 bits, then you get an 8-byte aligned address with the least amount of padding
it's a bit more work if you fill up the buffer starting with the lowest addresses
 
if(std::align(alignof(T), sizeof(T), ptr, available_space)) { /* ptr is aligned, available_space is updated, and it fits */ }
 
Xeo
I think I need to see some code to understand that right now
I'm kinda sleep deprived
@RMartinhoFernandes It returns an aligned ptr
 
@Xeo Or null if it doesn't fit.
 
Xeo
and takes a pointer to the space and the space size, no?
 
8:31 AM
It takes the ptr by reference.
 
Xeo
mhm
 
@Xeo Yes, that's ptr and available_space above.
 
@Xeo We should make a club.
 
Xeo
char buf[200];
char* p = &buf[2];
size_t avail = 198;
std::align(8, 24, p, avail);
// p == &buf[8], avail == 190 ?
 
Uh, is ratio_add<> an alias for std::ratio?
and not a separate type?
 
Xeo
8:37 AM
wait
I don't get it. My mind is too squishy right now
 
@Pubby Seems so.
@Xeo That would be p == &buf[8] and avail == 192.
Because aligning only took 6 bytes.
 
Xeo
Ah, align doesn't decrease avail by the size of the object?
 
No, it only accounts the space it took away by advancing the pointer.
 
Xeo
Damn, now I need another meta-information variable in my register_node...
And I need to adjust the allocation interface of my pools to allow for alignment parameters. :(
 
isn't the interface templated?
 
Xeo
8:41 AM
of the pools? no. They only care about raw bytes
 
well, at some higher level, I meant. The user shouldn't need to specify the alignment, if you can just call a templated allocation function which calls alignof/std::alignment_of internally
 
Xeo
And I can't exactly type them because I use them for allocating a bunch of different loaders + maybe metadata
Oh, that's what you mean
 
I have a very similar buffer in my STM lib :)
so been through a lot of these headaches
in my case it got really interesting when I realized I needed to be able to copy objects from the buffer, still without knowing their type... :)
 
Xeo
When I said interface I meant the allocate and deallocate functions of the pools. :)
@jalf pointer to templated function taking void*?
 
yeah
 
Xeo
8:45 AM
I had to use that in my homebrewn std::function implementation :D
Or rather, I just did instead of virtual functions
Nooo~ MSVC10 doesn't support std::align :(
 
I thought it supported all of the standard library.
 
Xeo
11 does
 
Xeo
I'm coding with 10 right now
 
9:13 AM
@Xeo what is type alignment all about 0_o?
@RMartinhoFernandes HNY2012 :) ( not a coupon code:D)
 
@Xeo just do it manually then. Is fairly easy to adjust a pointer to ensure alignment
 
@MrAnubis Took me a couple seconds to decypher :)
 
void* alloc(char* prev_obj, size_t size, size_t align) { return (prev_obj - size) & ~(align-1);}
just need to add a bounds check
 
@MrAnubis Some architectures forbid you from, let's say, accessing a 4-byte integer from an address that isn't a multiple of 4 (just some example). Some don't forbid it but doing so is not as fast.
 
also this assumes you fill the buffer up backwards, starting from the highest address
 
9:17 AM
The n in "address that isn't a multiple of n" is called the alignment for some type.
 
Xeo
@jalf "starting from the highest address" aren't you assuming something about the architecture here?
 
@Xeo Starting from the end of the buffer?
 
@Xeo only that there is a notion of an address being higher than another
which seems a fairly safe bet ;)
I just mean that you start from buf.end(), and work towards buf.begin()
 
@RMartinhoFernandes aah , got it , Thanks :)
 
Decrementing from a pointer at the end brings you to the start, no matter what architecture. It's mandatory.
 
Xeo
9:18 AM
@jalf And that the end is higher than the beginning
 
@Xeo that's how an array works. That's mandated by the standard ;)
 
@Xeo ptr < ptr + n // for n > 0
 
if you have a pointer to a position N in an array, and subtract some value x <=N then you get to a lower address in the same array
 
@RMartinhoFernandes - for x86 arch, is alignment just a type of speed-optimization then? IIRC, x86 (unlike Sparc) will let you be sloppy about alignment...
 
Xeo
@RMartinhoFernandes Yeah, but what about that bit masking stuff?
 
9:19 AM
@kfmfe04 Usually, yeah. But if you want to use SSE, then it's an error to ignore alignment, even on x86
 
@jalf ic - ty
 
oh right, that should be done on integers, not pointers
 
@Xeo Ah, that does sound implementation specific.
 
I ended up doing that, and just working with array offsets instead of pointers in my buffer
 
Ah, offsets.
 
Xeo
9:20 AM
@jalf I actually use an index too
 
it's pretty trivial to translate between an index into an array and a pointer into the same array, after all
 
Then the bit masking is just math.
 
and it's well-defined for (unsigned) integers
 
Xeo
I still don't get that masking thing for the proper alignment
 
sbi
@Xeo Seems I need to point out this article (PDF link). // @Ben
 
9:22 AM
If you have say, 8, 8-1= 7 = 0b00000111. ~7 = 0b11111000.
Build a zigamorph of appropriate size, negate it and mask.
 
damn, I screwed up the conditional expression parser. :(
 
sbi
Anyone here read Good Omens? This is pretty funny.
> Resolution #6: I will try to understand why Hell is a no-smoking area. I just think it's ridiculous having to stand around outside the gates, that's all.
 
@Xeo well, we know that alignments are always powers of two. Which means that the lower N bits will be zero
for alignment 8, the lower 3 bits will be zero, so given a pointer to some address, we can zero out the three lower bits to get a well-aligned address which might be a few bytes lower than the original one
 
Xeo
Ah, that's why you start from the back
 
by subtracting 1 from the alignment, I get a number where only those lower bits are set (8-1 == 7, and 7 is 0b0111), so I negate the whole thing to get a suitable mask
@Xeo yup
 
9:26 AM
Resolution #8: Stop Googling myself. lol...
 
@IntermediateHacker Somehow that sounds dirty.
typedef __rune_t        rune_t;
Found this on GCC's stddef.h.
 
hey, I fixed the Conditional Expression Parser!!!.... and fucked up the preprocessor. :(
 
of course the main problem with working with indices instead of pointers is that it only works if the array's starting address was well-aligned for any type
 
@RMartinhoFernandes Seems to be some Plan9 multibyte encoding thingy.
 
Ugh, Plan9.
 
9:37 AM
> In Plan 9, a rune is a 16-bit quantity representing a Unicode character.
Mystery solved.
 
Pity a rune can't represent any Unicode character.
0
Q: C++: Is it possible to detach the char* pointer from an std::string object?

markI am using the std::string type for my string manipulations. However, sometimes I need to keep the raw char* pointer, even after the original std::string object is destroyed (yes, I know the char* pointer references the HEAP and must eventually be disposed of). However, looks like there is no ...

 
HEAP is SERIOUS BUSINESS.
 
Heap of Extraordinary Arrays and Pointers.
 
user142019
Hello.
 
Heaplo.
 
user142019
9:43 AM
He can subclass std::string.
 
And do what? You can't prevent std::string from nuking the buffer.
 
user142019
Write a method that returns a copy using strcpy
 
No need to subclass then.
 
Or, you know, just keep the string object alive.
 
user142019
That's the best thing to do.
 
9:45 AM
@CatPlusPlus But the bloat! Or something like that.
 
user142019
Or copy the string object.
 
I wonder what caused the "need" to "detach" the buffer.
 
user142019
Or nothing.
 
user142019
C++ is an esoteric programming language anyway.
 
Stupidity.
 
user142019
9:47 AM
lol
 
Great, accepted one of the copy solutions.
 
user142019
"Yes I know it's on the heap." wait isn't that implementation-defined?
 
Anyone know of a list of common programming operators?
 
user142019
This is a list of operators in the C and C++ programming languages. All the operators listed exist in C++; the fourth column "Included in C", dictates whether an operator is also present in C. Note that C does not support operator overloading. When not overloaded, for the operators &&, ||, and , (the comma operator), there is a sequence point after the evaluation of the first operand. C++ also contains the type conversion operators const_cast, static_cast, dynamic_cast, and reinterpret_cast which are not listed in the table for brevity. The formatting of these operators means that their p...
 
List of Haskell operators would be more interesting.
 
9:49 AM
I know those, I'm looking for something with lots of operators
 
Already went through haskell's ops
 
No, you didn't.
 
How could you? With Haskell the possibilities are endless!
 
Well, the default ones
 
user142019
9:49 AM
Just google "<language> operators list".
 
@Pubby Perl.
 
mawning
 
Google "periodic table of the operators". You'll have work for a month.
 
Xeo
@RMartinhoFernandes I was just going to suggest that
 
Yay! A table!
 
user142019
9:51 AM
Perl is evil.
 
What's preferred, ** or ^ for exponentiation?
 
user142019
^
 
Perl uses **.
 
user142019
** is pointer to pointer.
 
Haskell uses ** too.
 
9:52 AM
^ is XOR.
 
@WTP And ^ is bitwise exclusive or.
 
user142019
Haskell uses ^ too.
 
user142019
pow(b, x)
 
^ is a pointer in Pascal.
 
9:53 AM
Pascal has pointers?
 
user142019
^ is a pointer to a managed object in C++/CLI.
 
How do you think you make linked lists in Pascal? ;)
 
It's called a handle. You lose.
 
user142019
That's the same.
 
9:55 AM
Whatever. "flip-flop"s are the bestest operators.
 
user142019
Use • for exponents, it isn't in use yet.
 
Shading languages have "swizzle".
 
Swizzling is cool.
 
user142019
Method swizzling?
 
There's also "mingle" from INTERCAL.
 
9:56 AM
Component swizzling.
 
And the "crazy" operator from Malbolge.
Oh, and how could I forget p5=>, which is Perl 6's "Perl 5 fatarrow" (yep, that's the name).
 
lol
 
user142019
FALSE has ø.
 

« first day (443 days earlier)      last day (4488 days later) »