internals

Computer Architecture: How do applications communicate with an operating system? [closed]

若如初见. 提交于 2019-11-29 18:25:27
Prelude: This is admittedly a fairly broad question regarding computer architecture, but one that I hear from others and wonder about quite often myself. I also don't think that there is a direct or quick answer to this. However, I was hoping someone well-versed in systems architecture could provide some insight. Some background: I am primarily a full-stack developer focusing mostly on web technologies and databases. I do have some background in C and tinkering with a good deal of low-level stuff, but that was a very long time ago and was non-academic. As such, I never got very deep into OS

How does JVM implement the varargs?

五迷三道 提交于 2019-11-29 13:50:44
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 stack refereneces to the strings, not just one reference to the array? It is implemented at compile time

Make internal classes visible to other assemblies

我怕爱的太早我们不能终老 提交于 2019-11-29 10:48:42
问题 Is it possible to make internal classes from my assembly visible to other assemblies? I know about the AssemblyInfo file and the [assembly: InternalsVisibleTo()] attribute, but it doesn't work in my case. The main purpose is to make it possible to call methods from LINQPAD, so this [assembly: InternalsVisibleTo("LINQPad")] doesn't work. I don't know why. In my project, I'm using dependency resolver, and it is hard to do such a thing in LINQPAD. Any suggestions? 回答1: I've just uploaded a new

Mockito Internals

与世无争的帅哥 提交于 2019-11-29 08:02:22
I'm trying to understand how Mockito's internals function. So far the code has been difficult for me to understand, and I'm looking for a high-level survey of the fundamental workings of Mockito. Mockito @ GrepCode I've written some sample code to demonstrate my current understanding: class C { String s; public void getS() { return s; } // ... } C cm = mock( C.class); when( cm.method() ).thenReturn( "string value"); As far as I can tell, the 'mock' method is only seeing the return value for cm.getS(). How can it know what the name of the method is (in order to stub it)? Also, how can it know

GNU STL string: is copy-on-write involved here?

拥有回忆 提交于 2019-11-29 06:47:25
问题 (Disclaimer: I don't know what the C++ standard might say about this..I know, I'm horrible) while operating on very large strings I noticed that std::string is using copy-on-write. I managed to write the smallest loop that would reproduce the observed behaviour and the following one, for instance, runs suspiciously fast: #include <string> using std::string; int main(void) { string basestr(1024 * 1024 * 10, 'A'); for (int i = 0; i < 100; i++) { string a_copy = basestr; } } when adding a write

Python generator objects: __sizeof__()

佐手、 提交于 2019-11-29 03:35:16
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 enlighten me. Martijn Pieters __sizeof__() does not do what you think it does. The method returns the

Internals of node.js. How does it actually work

谁说我不能喝 提交于 2019-11-28 22:46:10
问题 Perhaps somebody who implemented node.js module can explain the protocol between node.js queue processed on a single thread and a blocking IO operations that will be performed by a module. I suspect that it goes something like this: node.js thread registers a callback in a form of a closure and saves it with some correlation id. node.js invokes a method (which should perform blocking IO) on a module and passes method parameters and correlation id to it. module method spins off a thread and

How does event handling work internally within JavaScript?

爷,独闯天下 提交于 2019-11-28 20:47:05
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/nsJSEventListener.cpp SpiderMonkey itself doesn't have anything involving event handling. Events are purely a DOM

Internals of Python list, access and resizing runtimes

倖福魔咒の 提交于 2019-11-28 20:13:47
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 Python tuple have faster access times than a python list? Eli Bendersky Python's [] is implemented as an

How to get array of bits in a structure?

巧了我就是萌 提交于 2019-11-28 19:13:33
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 individual bits packed in a struct. They can be accessed individually, leaving the job of bit