internals

OCaml internals: Exceptions

点点圈 提交于 2019-11-28 18:46:17
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 perform worst. By looking at how OCaml interfaces with C ( http://caml.inria.fr/pub/docs/manual-ocaml

How does fork() know when to return 0?

耗尽温柔 提交于 2019-11-28 17:45:05
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 process and the correct PID for the parent process. This where it gets really confusing. This answer states

Confusion about how a getchar() loop works internally

大兔子大兔子 提交于 2019-11-28 14:04:08
I've included an example program using getchar() below, for reference (not that anyone probably needs it), and feel free to address concerns with it if you desire. But my question is: What exactly is going on when the program calls getchar() ? Here is my understanding (please clarify or correct me): When getchar is called, it checks the STDIN buffer to see if there is any input. If there isn't any input, getchar sleeps. Upon wake, getchar checks to see if there is any input, and if not, puts it self to sleep again. Steps 2 and 3 repeat until there is input. Once there is input (which by

What is INT 21h?

时间秒杀一切 提交于 2019-11-28 10:26:42
Inspired by this question How can I force GDB to disassemble? I wondered about the INT 21h as a concept. Now, I have some very rusty knowledge of the internals, but not so many details. I remember that in C64 you had regular Interrupts and Non Maskable Interrupts, but my knowledge stops here. Could you please give me some clue ? Is it a DOS related strategy ? From here : A multipurpose DOS interrupt used for various functions including reading the keyboard and writing to the console and printer. It was also used to read and write disks using the earlier File Control Block (FCB) method. DOS can

STL internals: deque implementation

Deadly 提交于 2019-11-28 09:54:20
I am using a std::deque for storing a large collection of items . I know that deques is implemented as a list of vectors. The size of those vectors cannot be set but I wander what is the algorithm for choosing that size. deque is implemented as a vector of vectors (a list of vectors would impede the constant time random access). The size of the secondary vectors is implementation dependent, a common algorithm is to use a constant size in bytes. My deque implementation, the one from GNU which is derived from the HP/SGI version, is not a list of vectors; at least, not an std::list of std::vector

How Do ncurses et. al. Work?

两盒软妹~` 提交于 2019-11-28 09:50:34
There are several libraries like ncurses that assist in making command-line GUIs. Simply put, how do they work? My first thought was that ncurses intercepts all keyboard input, and draws each "frame" by outputting it line-by-line normally. Closer inspection, however, reveals that each new frame overwrites the previous one. How does it modify lines that have already been outputted? Furthermore, how does it handle color? EDIT: The same question applies to anything with a "fancy" interface, like vim and emacs . Craig Text terminals have command sequences that do things like move the cursor to a

How can I access the ListViewItems of a WPF ListView?

馋奶兔 提交于 2019-11-28 08:28:55
Within an event, I'd like to put the focus on a specific TextBox within the ListViewItem's template. The XAML looks like this: <ListView x:Name="myList" ItemsSource="{Binding SomeList}"> <ListView.View> <GridView> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <!-- Focus this! --> <TextBox x:Name="myBox"/> I've tried the following in the code behind: (myList.FindName("myBox") as TextBox).Focus(); but I seem to have misunderstood the FindName() docs, because it returns null . Also the ListView.Items doesn't help, because that (of course) contains my bound business objects and no

How does JVM implement the varargs?

五迷三道 提交于 2019-11-28 07:36:45
问题 I recently got interested in such a feature in Java, as functions with variable number of arguments. This is a very cool feature. But I'm interested: void method(int x, String.. args) { // Do something } How is this actually implemented on the runtime level? What comes to my mind, is that when we have a call: method(4, "Hello", "World!"); The last two arguments are internally transformed into an array, that is passed to the method. Am I right about this, or the JVM actually pushes in the

Alignment along 4-byte boundaries

橙三吉。 提交于 2019-11-28 06:03:54
I recently got thinking about alignment... It's something that we don't ordinarily have to consider, but I've realized that some processors require objects to be aligned along 4-byte boundaries. What exactly does this mean, and which specific systems have alignment requirements? Suppose I have an arbitrary pointer: unsigned char* ptr Now, I'm trying to retrieve a double value from a memory location: double d = **((double*)ptr); Is this going to cause problems? It can definitely cause problems on some systems. For example, on ARM-based systems you cannot address a 32-bit word that is not

What is [DllImport(“QCall”)]?

浪子不回头ぞ 提交于 2019-11-27 18:15:33
Many methods in the .Net library are implemented in native code. Those that come from the framework itself are marked with [MethodImpl(MethodImplOptions.InternalCall)] . Those that come from some unmanaged DLL are marked with [DllImport] (e.g. [DllImport("kernel32.dll")] ). So far nothing unusual. But while writing answer for another question , I discovered there are many methods marked with [DllImport("QCall")] . They seem to be internal implementation of .Net (e.g. GC._Collect() ). My question is: What exactly does [DllImport("QCall")] mean? What is the difference between [DllImport("QCall")