internals

C++11 internal std::string representation (libstdc++)

六月ゝ 毕业季﹏ 提交于 2019-12-22 04:37:33
问题 How std::string is internally represented in c++11 (libstdc++)? While digging inside the implementation, I found: /* A string looks like this: * * [_Rep] * _M_length * [basic_string<char_type>] _M_capacity * _M_dataplus _M_refcount * _M_p ----------------> unnamed array of char_type * * Where the _M_p points to the first character in the string, and * you cast it to a pointer-to-_Rep and subtract 1 to get a * pointer to the header. * * This approach has the enormous advantage that a string

How does c# figure out the hash code for an object?

荒凉一梦 提交于 2019-12-21 07:35:32
问题 This question comes out of the discussion on tuples. I started thinking about the hash code that a tuple should have. What if we will accept KeyValuePair class as a tuple? It doesn't override the GetHashCode() method, so probably it won't be aware of the hash codes of it's "children"... So, run-time will call Object.GetHashCode(), which is not aware of the real object structure. Then we can make two instances of some reference type, which are actually Equal, because of the overloaded

What Ruby technique does Rails use to make my controller methods render views?

坚强是说给别人听的谎言 提交于 2019-12-21 03:47:40
问题 Just curious if anybody knows what Ruby technique is used to accomplish the following in the Rails framework. If I don't write, say, an index method on a Rails controller, Rails will still render the index view file if the URL matches that route. That makes sense, because my controller inherits from a parent class, which must have its own index method. However, if I do define an index method, and only tell it to set an instance variable, it still renders the appropriate view. For example: def

Create a process from a driver

浪子不回头ぞ 提交于 2019-12-19 08:12:41
问题 Is there a way to create a user-mode process from kernel-mode on Windows NT platform (XP-W7)? EDIT: I must install only the driver. This is a specific of the project. 回答1: To create a valid win32 process the driver must communicate with CSRSS (what is completely undocumented). So I ended up by queuing a user-mode APC and allocating virtual memory for the APC code in the context of the existing win32 process (that code will call CreateProcess and do the job). It is a tricky way but it works.

How to find out which .c file contains the .c functions of R internals, on Windows?

扶醉桌前 提交于 2019-12-18 14:57:42
问题 I want to view the source code of R's match.call function. As it is an internal function, I downloaded the R source code, went to ./src/main/names.c and looked for match.call there. Thus, I found out that the corresponding .c function is called do_matchcall . Ok, but how can I find out which of the dozens of .c files in ./src/main/ contains the function do_matchcall ? Btw I'm using a Windows machine, in case that makes a difference. 回答1: As a Windows user, here are a couple of options. The

How to find out which .c file contains the .c functions of R internals, on Windows?

不打扰是莪最后的温柔 提交于 2019-12-18 14:57:35
问题 I want to view the source code of R's match.call function. As it is an internal function, I downloaded the R source code, went to ./src/main/names.c and looked for match.call there. Thus, I found out that the corresponding .c function is called do_matchcall . Ok, but how can I find out which of the dozens of .c files in ./src/main/ contains the function do_matchcall ? Btw I'm using a Windows machine, in case that makes a difference. 回答1: As a Windows user, here are a couple of options. The

Why was the object_id for true and nil changed in ruby2.0?

萝らか妹 提交于 2019-12-18 11:49:29
问题 I came across this ruby object_id allocation question sometime back and then read this awesome article which talks about VALUE and explains why object_id of true, nil and false the way they are. I have been toying with ruby2.0 object_id when I found the apparent change that has been made regarding object_id of true and nil. forbidden:~$ ruby -v ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux] forbidden:~$ forbidden:~$ irb irb(main):001:0> true.object_id => 20 irb(main):002:0> false

Reference for R wizards

南笙酒味 提交于 2019-12-18 11:47:34
问题 Based on this answer, I learned of a special class of internal functions that can be accessed from R: a set of functions accessed via .Internal(specialFunction) . If one queries ?.Internal this excerpt may be found: Only true R wizards should even consider using this function, and only R developers can add to the list of internal functions. I want to master potions and defense against the Dark Arts for my OWLs interesting R functions. Where can R wizards find a list and description of the

Mockito Internals

二次信任 提交于 2019-12-18 05:13:09
问题 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

How Do ncurses et. al. Work?

你离开我真会死。 提交于 2019-12-17 19:12:48
问题 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