internals

How are java interfaces implemented internally? (vtables?)

痴心易碎 提交于 2019-11-27 17:23:53
C++ has multiple inheritance. The implementation of multiple inheritance at the assembly level can be quite complicated, but there are good descriptions online on how this is normally done (vtables, pointer fixups, thunks, etc). Java doesn't have multiple implementation inheritance, but it does have multiple interface inheritance, so I don't think a straight forward implementation with a single vtable per class can implement that. How does java implement interfaces internally? I realize that contrary to C++, Java is Jit compiled, so different pieces of code might be optimized differently, and

How do databases work internally? [closed]

北城余情 提交于 2019-11-27 16:44:25
I've been working with databases for the last few years and I'd like to think that I've gotten fairly competent with using them. However I was reading recently about Joel's Law of Leaky Abstractions and I realised that even though I can write a query to get pretty much anything I want out of a database, I have no idea how the database actually interprets the query. Does anyone know of any good articles or books that explain how databases work internally? Some specific things I'm interested in are: What does a database actually do to find out what matches a select statement? How does a database

Python generator objects: __sizeof__()

大兔子大兔子 提交于 2019-11-27 16:04:17
问题 This may be a stupid question but I will ask it anyway. I have a generator object: >>> def gen(): ... for i in range(10): ... yield i ... >>> obj=gen() I can measure it's size: >>> obj.__sizeof__() 24 It is said that generators get consumed: >>> for i in obj: ... print i ... 0 1 2 3 4 5 6 7 8 9 >>> obj.__sizeof__() 24 ...but obj.__sizeof__() remains the same. With strings it works as I expected: >>> 'longstring'.__sizeof__() 34 >>> 'str'.__sizeof__() 27 I would be thankful if someone could

Order of static constructors/initializers in C#

二次信任 提交于 2019-11-27 14:38:37
While working on a C# app I just noticed that in several places static initializers have dependencies on each other like this: static private List<int> a = new List<int>() { 0 }; static private List<int> b = new List<int>() { a[0] }; Without doing anything special that worked. Is that just luck? Does C# have rules to resolve this? Edit: (re: Panos) In a file lexical order seems to be king? what about across files? In looking I tried a cyclical dependency like this: static private List<int> a = new List<int>() { b[0] }; static private List<int> b = new List<int>() { a[0] }; and the program didn

How does event handling work internally within JavaScript?

拜拜、爱过 提交于 2019-11-27 13:09:35
问题 Specifically Spidermonkey. I know you write functions and attach them to events to handle them. Where is the onClick handler defined and how does the JS engine know to fire onClick events when the user clicks? Any keywords, design patterns, links, etc are appreciated. UPDATE Aggregating links I find useful here: http://www.w3.org/TR/DOM-Level-2-Events/events.html https://github.com/joyent/node/blob/master/src/node_events.cc http://mxr.mozilla.org/mozilla/source/dom/src/events

Internals of Python list, access and resizing runtimes

穿精又带淫゛_ 提交于 2019-11-27 12:48:56
问题 Is Python's [] a list or an array? Is the access time of an index O(1) like an array or O(n) like a list? Is appending/resizing O(1) like a list or O(n) like an array, or is it a hybrid that can manage O(1) for accessing and resizing? I read here that array access is really slow in Python. However, when I wrote a memoized version of a recursive fibonacci procedure using both a dictionary (Python's dictionary is suppose to be really fast) and a list, they had equal times. Why is this? Does a

How to get array of bits in a structure?

六月ゝ 毕业季﹏ 提交于 2019-11-27 12:05:22
问题 I was pondering (and therefore am looking for a way to learn this, and not a better solution ) if it is possible to get an array of bits in a structure. Let me demonstrate by an example. Imagine such a code: #include <stdio.h> struct A { unsigned int bit0:1; unsigned int bit1:1; unsigned int bit2:1; unsigned int bit3:1; }; int main() { struct A a = {1, 0, 1, 1}; printf("%u\n", a.bit0); printf("%u\n", a.bit1); printf("%u\n", a.bit2); printf("%u\n", a.bit3); return 0; } In this code, we have 4

OCaml internals: Exceptions

穿精又带淫゛_ 提交于 2019-11-27 11:49:18
问题 I'm curious to know how exceptions are dealt with in OCaml runtime to make them so lightweight. Do they use setjmp/longjmp or do they return a special value in each function, and propagate it? It seems to me that longjmp would put a little strain on the system, but only when an exception is raised, while checking for each function return value would need to check for every and each value after calling a function, which seems to me would put a lot of checks and jumps, and it seems it would

What constitutes a merge conflict in Git?

試著忘記壹切 提交于 2019-11-27 11:27:04
How does git determine that a particular merge has a conflict and what the conflict is? My guess would go something like this: if the two commits being merged have a common parent commit, and if they have both changed line X from what the parent had, that's a conflict. What complicates my understanding is: "Changing line X" can mean replacing it with several new lines, and that's still shown as one conflict (version A has this one line, and version B has these 5 lines, or whatever) If you did insert lines in one of the commits, a dumber algorithm would think that all subsequent lines had

How does fork() know when to return 0?

吃可爱长大的小学妹 提交于 2019-11-27 10:42:18
问题 Take the following example: int main(void) { pid_t pid; pid = fork(); if (pid == 0) ChildProcess(); else ParentProcess(); } So correct me if I am wrong, once fork() executes a child process is created. Now going by this answer fork() returns twice. That is once for the parent process and once for the child process. Which means that two separate processes come into existence DURING the fork call and not after it ending. Now I don't get it how it understands how to return 0 for the child