10,043 reputation
12343
bio website
location
age
visits member for 3 years, 10 months
seen 38 mins ago

Aug
6
comment Stable, Hash Based Symmetrical Difference
Well, there are hash sets that maintain insertion order. I think that ought to help, but I can't quite put my finger on it.
Aug
6
comment When would you want two references to the same object?
@MarkJ Linear types aren't just an ideal, much existing code unknowingly conforms to it because it's the semantically correct thing for quite a few cases. It does have potential performance advantages (but neither for reference counting nor tracing GCs, it only helps when you use a different strategy that actually exploits that knowledge to omit both refcounts and tracing). More interesting is its application to simple, deterministic resource management. Think RAII and C++11 move semantics, but better (applies more often and mistakes are caught by the compiler).
Aug
6
comment Knowing the range of variable types needed
Let us continue this discussion in chat.
Aug
6
comment Knowing the range of variable types needed
I wasn't talking about the "I only need eight bits at most" niche (which is reasonably common), I was talking about the "you have so many integers that using a smaller type actually makes any appreciable difference" niche, which is far more narrow. How many classes have hundred int members? And how often will you have millions of such objects? As an analogy, OP is asking about going out without sun screen and you spend your whole answer talking about the virtues of covering all skin with light cloth, because that's what it takes in the Sahara.
Aug
6
comment Knowing the range of variable types needed
If you carefully noted that there are occasions where shrinking integers by 25% is useful, I'd be fully with you. But that's not what this answer does. It speaks about a quite narrow niche in absolute terms with unjustified vigor.
Aug
6
comment Knowing the range of variable types needed
Okay, let's get down to specifics. I take issue with this part: "People often just use int, or allow var to determine what the variable type should be. This is inefficient (but not terribly so)". And the advise to use a smaller type for loops, for which I see no justification except an aesthetic choice dressed up as relevant experience (" people like me who like to get every ounce of performance").
Aug
6
comment Knowing the range of variable types needed
You say you "get tickled pink" by using the "most perfect" datatype for the situation. Since you spoke specifically about loop variables I can't imagine you were talking about memory savings. So please explain what you meant if I misunderstood.
Aug
6
comment Knowing the range of variable types needed
I call BS on the loop being faster. At best, it uses the same registers and operations and comes out equally fast; at worst it has to do some sign extensions and winds up ever so slightly slower. Please give evidence of your assertion.
Aug
6
comment Knowing the range of variable types needed
Be aware that many variables (and temporary values) in programs never occupy any memory at all, or rather occupy registers which are of fixed size anyway (erasing any size difference by rounding up to the register size).
Aug
5
comment Are bloom filters actually faster than hashes, even taking in account cache?
You have k bits, period. All elements affect the same fixed number of bits, that's why the false positive rate depends on the number of entries.
Aug
5
comment Are bloom filters actually faster than hashes, even taking in account cache?
What completely distant places? There are only m bits. That probably fits in a single register, or at worst a single cache line.
Aug
4
comment Should you avoid adding unecessary stack frames?
@Doval Creating a closure does that. Calling it adds a stack frame like any other function call. Otherwise agreed.
Aug
4
comment Why do VMs not execute the assembly directly?
There is no additional step of compilation. The textual representation is a ad-hoc debugging help for humans, the only canonical representation is the binary representation. (This is yet another difference to most real machines.) Code generation for the VM doesn't produce strings like push 1 push 2, it produces the "ones and zeros" right away.
Aug
2
comment When would you want two references to the same object?
@SJuan76 The "less common case" is solely about taking from local variables, anything involving data structures falls under the last point.
Aug
2
answered When would you want two references to the same object?
Aug
2
comment Is my 'variable-storing area' basically a 'heap'?
@Prog I also suggest you do some research on "low-level stuff" (there are some excellent questions on Stack Overflow and on this site). The VM will almost certainly look different (most VMs do) but it certainly doesn't hurt to know what real machines do.
Aug
2
comment Is my 'variable-storing area' basically a 'heap'?
@Prog Let's talk C (and ignore the existence of registers). Specifically void f() { int x; int y; ... }. The prologue of the function will contain add sp, 8 which advances the stack pointer by 8 bytes (actually more but let's ignore that too). sp is a pointer to the end/top of the stack which is a region of RAM. The compiler decided to put x first, so any time it needs to refer to x in the generated code, it loads and stores [sp-8] ("the value at the address stored in sp minus 4"), and for y it uses [sp-4]. This knowledge is deeply integrated into the generated code.
Aug
2
comment Is my 'variable-storing area' basically a 'heap'?
@Prog I tried to address (1) and (2) in an edit. Lastly, about the use of heap: How would you create a linked list or a tree data structure using only a fixed set of scalar variables?
Aug
2
revised Is my 'variable-storing area' basically a 'heap'?
added 778 characters in body
Aug
2
revised Is my 'variable-storing area' basically a 'heap'?
deleted 6 characters in body