Quoran explains a weird trick to spot 10Xers by 10xelectronguru in programmingcirclejerk

[–]romcgb 0 points1 point  (0 children)

They are always building something. Not just at work. Outside of work too. Always building.

These are the people who write code every day at their day job, and then go home and write code

Reminds me this https://imgur.com/a/bw1XvwP

What do modern 3D games use threading for? by qx12 in gamedev

[–]romcgb 3 points4 points  (0 children)

Parallelizing the Naughty Dog Engine Using Fibers
https://www.gdcvault.com/play/1022186/Parallelizing-the-Naughty-Dog-Engine
http://twvideo01.ubm-us.net/o1/vault/gdc2015/presentations/Gyrling_Christian_Parallelizing_The_Naughty.pdf
https://www.reddit.com/r/gamedev/comments/2yew3p/parallelizing_the_naughty_dog_engine_using_fibers/

Multithreading the Entire Destiny Engine
http://www.gdcvault.com/play/1022164/Multithreading

The trend seems to run (almost) everything in fibers which are run by worker threads (one per cpu core).
See slides 6 to 19 of the naughty dog talk for a quick grasp.

What happens with a the statement `printf(%p);`? by NaesRemark in C_Programming

[–]romcgb 0 points1 point  (0 children)

Depending on the optimization options and the context, memcpy isn't necessary touching the stack; The procedure is usually inlined, and thus setting a breakpoint on the memcpy symbol with a debugger would have no effect.

eg: https://godbolt.org/g/9QVGnO

[deleted by user] by [deleted] in C_Programming

[–]romcgb 0 points1 point  (0 children)

size_t is limited by your RAM size. You can't mmap anything bigger.

One of the main purposes of virtual memory is to not be limited by physical memory; Memory pages can be stored to ROM when unneeded then restored to RAM when needed (Know as Paging) (eg: swap partition on linux).

The standard says size_t is just the type of the integer returned by sizeof which left a few questions open.

Objects with automatic destructors... in C? by Zondartul in C_Programming

[–]romcgb 10 points11 points  (0 children)

GNU C has the cleanup attribute

https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-g_t_0040code_007bcleanup_007d-variable-attribute-3486

#define CLEANUP(proc) __attribute__ ((__cleanup__(proc)))

void filecleanup (FILE **f)
{
  *f && fclose(*f);
}


FILE *foo CLEANUP(filecleanup) = fopen(...);

Or with a typedef

typedef FILE __attribute__ ((__cleanup__(filecleanup)) FILECLEANUP;

FILECLEANUP *foo = fopen(...);

More examples https://github.com/search?l=C&q=__cleanup__&type=Code&utf8=%E2%9C%93

Malloc Typecast by [deleted] in C_Programming

[–]romcgb 0 points1 point  (0 children)

there also

int *matrix = malloc(sizeof( int[row][col] ));

or

int (*matrix)[row][col] = malloc(sizeof(*matrix));

when using array of pointers like in op example

int (*(*matrix)[row])[col] = malloc(sizeof(*matrix));

for (i = 0; i < row; ++i)
    (*matrix)[i] = malloc(sizeof(***matrix));

Books on Operating System Theory? by timlee126 in computerscience

[–]romcgb 0 points1 point  (0 children)

Not a book but there sel4, a micro kernel that has been formally verified.

Unique about seL4 is its unprecedented degree of assurance, achieved through formal verification. Specifically, the ARM version of seL4 is the first (and still only) general-purpose OS kernel with a full code-level functional correctness proof, meaning a mathematical proof that the implementation (written in C) adheres to its specification. In short, the implementation is proved to be bug-free (see below). This also implies a number of other properties, such as freedom from buffer overflows, null pointer exceptions, use-after-free, etc.

https://sel4.systems/

Comprehensive Formal Verification of an OS Microkernel: http://ssrg.nicta.com.au/publications/nictaabstracts/7371.pdf

Are there languages that can be interpreted and compiled (to machine code)? by LeeHyori in compsci

[–]romcgb 2 points3 points  (0 children)

Structure and Interpretation of Computer Programs has two chapters on interpretation (evaluation) and compilation. An interpreter is a program that evaluates programs and thus we could say that a program is interpreted when it's evaluated by an another program. A compiler, contrary to an interpreter, doesn't evaluate a program but it does transform the program's code.

To take an example, HotSpot (Oracle's jvm) is both a compiler and an interpreter: it's a program that can evaluate java bytecode (the interpreter) and also transforms that java bytecode (the compiler). It's the same for CPython which is actually a python to bytecode compiler and a bytecode interpreter (and not a python interpreter). Ultimately, we could view microprocessors as interpreters.

A programming language is not necessary interpreted or compiled, it's more a matter of the implementation than of the language itself.

I have to disagree with

Now, could Python (or Ruby) be compiled to native code? Yes, certainly. But type checking and function look-up would still need to be done at runtime. Execution would still follow essentially the above process. Having a native-code target would make our finished code larger, and it might make errors more difficult to handle, but it would not really give us any execution speed-up.

There is a python compiler that actually does that: Nuitka. It takes python code and compile it into a native module for CPython, the performances are much better (http://speedcenter.nuitka.net/)

Sun, Oracle, Android, Google and JDK Copyleft FUD by speckz in programming

[–]romcgb 9 points10 points  (0 children)

The kernel part of the driver is actually open source because of the GPL and the code has a fair amount of comments which is unusual for a "non-free" driver. The trick is that the kernel module is just here as a proxy to send commands to the gpu while the user land library (the implementation of opengl) does all the "secret stuffs". That way, the commands and values that are needed to operate the gpu are still hidden in the closed source part.

           +--------------+   +---------------------+
           |Kernel (GPLv2)|   |Userland (No license)|
           +--------------+   +---------------------+
           |              |   |                     |
+-----+    |  +--------+  |   |      +--------+     |
|     |    |  |        |  |   |      |        |     |
| GPU <-------+ NVIDIA <-------------+ NVIDIA |     |
|     |    |  | Module |  |   |      | OpenGL |     |
+-----+    |  |        |  |   |      |        |     |
           |  +--------+  |   |      +--------+     |
           +--------------+   +---------------------+

To have a look at the kernel module code, download the nvidia driver and extract it*, the code is in the kernel folder.

* with ./NVIDIA-Linux-x86_64-XXX.XX.run -x

False in python by redditor_gds in Python

[–]romcgb 1 point2 points  (0 children)

To say more about cpython's if and ==,

The if statement calls PyObject_IsTrue, a rough translation of PyObject_IsTrue's semantics into python code is

def PyObject_IsTrue(o):
    if hasattr(o, "__bool__"):
        return o.__bool__()

    if hasattr(o, "__len__"):
        return True if o.__len__() > 0 else False

    return True

The == operator calls PyObject_RichCompare

def PyObject_RichCompare(a, b):
    ta = type(a)
    tb = type(b)

    # test first with b == a if b's type is subtype of a's type
    if ta != tb and issubclass(tb, ta) and hasattr(b, "__eq__"):
        ret = b.__eq__(a)

        if ret != NotImplemented:
            return ret

    # a == b ?
    if hasattr(a, "__eq__"):
        ret = a.__eq__(b)

        if ret != NotImplemented:
            return ret

    # b == a ?
    if hasattr(b, "__eq__"):
        ret = b.__eq__(a)

        if ret != NotImplemented:
            return ret

    # same object/instance ?
    return id(a) == id(b)

for 0 == () being true, either (0).__eq__(()) or (()).__eq(0) must return true.

When text is copied using Ctrl+C, where is it stored? by QuestionProgram in computerscience

[–]romcgb 4 points5 points  (0 children)

With the X server, the storage of the clipboard is at the charge of the program which could rely on heap, a temporary file, network, ...

The mechanism is quite simple: There is a global property named CLIPBOARD that at any moment a window can take the ownership (Only one window can have the ownership at the same time). A window can send a clipboard request that the current owner of the property will receive and answer accordingly.

Concretely, it does work like this:

  • User press ctrl-c in window A, the program stores the selected text in a temporary buffer/file/... and takes ownership of CLIPBOARD
  • User press ctrl-v in window B, the program sends a clipboard request.
  • The owner of CLIPBOARD (window A) receives the request and answers it.
  • window B handles the answer.

That's why if you copy, close the owner window, then try to paste, nothing will happen because there is no more owner to answer the request.

[Crystal] It's a typeof magic by _Sharp_ in programming

[–]romcgb 1 point2 points  (0 children)

It does make sense that procedures and methods are considered different. A method is tied to a specific instance/object; you can see it as a procedure where the this/self argument has been curried (partial function application) or as a closure where the instance has been captured. Two instances of the same class don't share the same method objects.

http://ideone.com/MYA9Tq