Update
This commit is contained in:
parent
bb3a0d81d6
commit
1ccdf27364
8 changed files with 112 additions and 11 deletions
3
c.md
3
c.md
|
@ -173,4 +173,5 @@ RETURN_TYPE myFunction (TYPE1 param1, TYPE2 param2, ...)
|
|||
- [Pascal](pascal.md)
|
||||
- [Fortran](fortran.md)
|
||||
- [LISP](lisp.md)
|
||||
- [FORTH](forth.md)
|
||||
- [FORTH](forth.md)
|
||||
- [memory management](memory_management.md) in C
|
|
@ -1678,8 +1678,8 @@ TODO
|
|||
|
||||
## Where To Go Next
|
||||
|
||||
We haven't covered the whole of C, not even close, but you should have pretty solid basics now. Now you just have to go and write a lot of C programs, that's the only way to truly master C. WARNING: Do not start with an ambitious project such as a 3D game. You won't make it and you'll get demotivated. Start very simple (a Tetris clone perhaps?).
|
||||
We haven't nearly covered the whole of C, but you should have pretty solid basics now. Now you just have to go and write a lot of C programs, that's the only way to truly master C. WARNING: Do not start with an ambitious project such as a 3D game. You won't make it and you'll get demotivated. Start very simple (a Tetris clone perhaps?).
|
||||
|
||||
You should definitely learn about common [data structures](data_strucutre.md) ([linked lists](linked_list.md), [binary trees](binary_tree.md), [hash tables](hash.md), ...) and [algorithms](algorithm.md) ([sorting](sorting.md), [searching](search.md), ...). Also take a look at basic [licensing](license.md). Another thing to learn is some [version control system](vcs.md), preferably [git](git.md), because this is how we manage bigger programs and how we collaborate on them. To start making graphical programs you should get familiar with some library such as [SDL](sdl.md).
|
||||
You should definitely learn about common [data structures](data_strucutre.md) ([linked lists](linked_list.md), [binary trees](binary_tree.md), [hash tables](hash.md), ...) and [algorithms](algorithm.md) ([sorting](sorting.md), [searching](search.md), ...). As an advanced programmer you should definitely know a bit about [memory management](memory_management.md). Also take a look at basic [licensing](license.md). Another thing to learn is some [version control system](vcs.md), preferably [git](git.md), because this is how we manage bigger programs and how we collaborate on them. To start making graphical programs you should get familiar with some library such as [SDL](sdl.md).
|
||||
|
||||
A great amount of experience can be gained by contributing to some existing project, collaboration really boosts your skill and knowledge of the language. This should only be done when you're at least intermediate. Firstly look up a nice project on some git hosting site, then take a look at the bug tracker and pick a bug or feature that's easy to fix or implement (low hanging fruit).
|
||||
|
|
14
copyright.md
14
copyright.md
|
@ -1,22 +1,22 @@
|
|||
# Copyright
|
||||
|
||||
Copyright (better called *copyrestriction* or *copywrong*) is one of many types of so called "[intellectual property](intellectual_property.md)" (IP), a legal concept that allows "ownership", i.e. restriction and [censorship](censorship.md) of certain kinds of [information](information.md), for example prohibition of sharing useful information or improving art. Copyright specifically allows the copyright holder (not necessarily the author) a monopoly (practically absolute power) over [art](art.md) creations such as images, songs or texts, which include source code of computer [programs](program.md). Copyright is a [capitalist](capitalism.md) mechanism for creating [artificial scarcity](artificial_scarcity.md), enabling censorship and elimination of the [public domain](public_domain.md) (a pool of freely shareable works that people could easily share, utilize and enjoy). Copyright is not to be confused with [trademarks](trademark.md), [patents](patent.md) and other kinds of "intellectual property". Copyright is symbolized by C in a circle or in brackets: (C), which is often accompanies by the phrase "all rights reserved".
|
||||
Copyright (better called *copyrestriction* or *copywrong*) is one of many types of so called "[intellectual property](intellectual_property.md)" (IP), a legal concept that allows "ownership", i.e. restriction, [censorship](censorship.md) and artificial [monopoly](monopoly.md) on certain kinds of [information](information.md), for example prohibition of sharing or viewing useful [information](information.md) or improving [art](art.md) works. Copyright specifically allows the copyright holder (not necessarily the author) a monopoly (practically absolute power) over [art](art.md) creations such as images, songs or texts, which also include source code of computer [programs](program.md). Copyright is a [capitalist](capitalism.md) mechanism for creating [artificial scarcity](artificial_scarcity.md), enabling censorship and elimination of the [public domain](public_domain.md) (a pool of freely shared works that anyone can use and benefit from). Copyright is not to be confused with [trademarks](trademark.md), [patents](patent.md) and other kinds of "intellectual property", which are similarly [harmful](harmful.md) but legally different. Copyright is symbolized by C in a circle or in brackets: (C), which is often accompanies by the phrase "all rights reserved".
|
||||
|
||||
When someone creates something that can even remotely be considered artistic expression (even such things as e.g. a mere collection of already existing things), he automatically gains copyright on it, without having to register it, announce it or let it be known anywhere in any way. He then practically has a full control over the work and can successfully sue anyone who basically just touches the work in any way. Therefore **any code without a [free](free_software.md) license attached is implicitly fully "owned" by its creator** (so called "all rights reserved") and can't be used by anyone without permission. It is said that copyright can't apply to ideas (ideas are covered by [patents](patent.md)), only to expressions of ideas, however that's [bullshit](bs.md), the line isn't clear and is arbitrarily drawn by judges; for example regarding stories in books it's been established that the story itself can be copyrighted, not just its expression (you can't rewrite the Harry Potter story in different words and start selling it).
|
||||
When someone creates something that can even remotely be considered artistic expression (even such things as e.g. a mere collection of already existing things), he automatically gains copyright on it, without having to register it, pay any tax, announce it or let it be known anywhere in any way. He then practically has a full control over the work and can successfully sue anyone who basically just touches the work in any way (even unknowingly and unintentionally). Therefore **any work (such as computer code) without a [free](free_software.md) license attached is implicitly fully "owned" by its creator** (so called "all rights reserved") and can't be used by anyone without permission. It is said that copyright can't apply to ideas (ideas are covered by [patents](patent.md)), only to expressions of ideas, however that's [bullshit](bs.md), the line isn't clear and is arbitrarily drawn by judges; for example regarding stories in books it's been established that the story itself can be copyrighted, not just its expression (e.g. you can't rewrite the [Harry Potter](harry_potter.md) story in different words and start selling it).
|
||||
|
||||
As if copyright wasn't bad enough of a [cancer](cancer.md), **there usually exist extra oppressive copyright-like restrictions called related rights or neighboring rights such as "[moral rights](moral_rights.md)", "[personal rights](personal_rights.md)" etc.** Such "rights" differ a lot by country and can be used to restrict and censor even copyright-free works. This is a stuff that makes you want to commit [suicide](suicide.md). Waivers such as [CC0](cc0.md) try to waive copyright as well as neighboring rights (to what extent neighboring rights can be waived is debatable though).
|
||||
|
||||
The current extreme form of copyright (as well as other types of IP such as software patents) has been highly criticized by many people, even those whom it's supposed to "protect" (small game creators, musicians etc.). Strong copyright laws basically benefit [corporations](corporation.md) and "trolls" on the detriment of everyone else. It smothers creativity and efficiency by prohibiting people to reuse, remix and improve already existing works. Most people are probably for *some* form of copyright but still oppose the current extreme form which is pretty crazy: **copyright applies to everything without any registration or notice and last usually 70 years (!!!) AFTER the author has died (!!!)** and is already rotting in the ground. This is 100 years in some countries. In some countries it is not even possible to waive copyright to own creations. Some people, including [us](lrs.md), are against the very idea of copyright (those may either use waivers such as [CC0](cc0.md) or [unlicense](unlicense.md) or protest by not using any licenses and simply ignoring copyright which however will actually discourage other people from reusing their works). Though copyright was originally intended to ensure artists can make living with their works, it has now become the tool of states and corporations for universal censorship, control, bullying, creating scarcity and [bullshit jobs](bullshit_job.md); states can use copyright to for example take down old politically inconvenient books shared on the Internet even if such takedowns do absolute not serve protection of anyone's living but purely political interests.
|
||||
The current extreme form of copyright (as well as other types of IP such as software patents) has been highly criticized by many people, even those whom it's supposed to "protect" (small game creators, musicians etc.). Strong copyright laws basically benefit mainly [corporations](corporation.md) and "trolls" on the detriment of everyone else. It smothers creativity and efficiency by prohibiting people to reuse, remix and improve already existing works -- something that's crucial for art, science, education and generally just making any kind of progress. Most people are probably for *some* form of copyright but still oppose the current extreme form which is pretty crazy: **copyright applies to everything without any registration or notice and last usually 70 years (!!!) AFTER the author has died (!!!)** and is already rotting in the ground. This is 100 years in some countries. In some countries it is not even possible to waive copyright to own creations -- just think about what kind of twisted society we are living in when it PROHIBITS people from making a selfless donation of their own creations to others. Some people, including [us](lrs.md), are against the very idea of copyright (those may either use waivers such as [CC0](cc0.md) or [unlicense](unlicense.md) or protest by not using any licenses and simply ignoring copyright which however will actually discourage other people from reusing their works). Though copyright was originally intended to ensure artists can make living with their works, it has now become the tool of states and corporations for universal censorship, control, bullying, surveillance, creating scarcity and [bullshit jobs](bullshit_job.md); states can use copyright to for example take down old politically inconvenient books shared on the Internet even if such takedowns do absolute not serve protection of anyone's living but purely political interests.
|
||||
|
||||
Prominent critics of copyright include [Lawrence Lessig](lessig.md) (who established [free culture](free_culture.md) and [Creative Commons](creative_commons.md)) as a response), [Nina Paley](nina_paley.md) and [Richard Stallman](rms.md). There are many movements and groups opposing copyright or its current form, most notably e.g. the [free culture](free_culture.md) movement, [free software](free_software.md) movement, [Creative Commons](creative_commons.md) etc.
|
||||
Prominent critics of copyright include [Lawrence Lessig](lessig.md) (who established [free culture](free_culture.md) and [Creative Commons](creative_commons.md) as a response), [Nina Paley](nina_paley.md) and [Richard Stallman](rms.md). There are many movements and groups opposing copyright or its current form, most notably e.g. the [free culture](free_culture.md) movement, [free software](free_software.md) movement, [Creative Commons](creative_commons.md) etc.
|
||||
|
||||
The book *Free Culture* by Lessig talks, besides others, about how copyright has started and how it's been shaped by corporations to becoming their tool for monopolizing art. The concept of copyright has appeared after the invention of [printing press](printing_press.md). The so called *Statute of Anne* of 1710 allowed the authors of books to control their copying for **14 years** and only after **registartion**. The term could be prolonged by anothert 14 years if the author survived. The laws started to get more and more strict as control of information became more valued and eventually the term grew to **life of author plus 70 years**, without any need for registration or deposit of the copy of the work. Furthermore with new technologies, the scope of copyright has also extended: if copyright originally only limited *copying* of books, in the Internet age it started to cover basically any use, as any manipulation with digital data in the computer age requires making local copies. Additionally the copyright laws were passing despite being unconstitutional as the US constitution says that copyright term has to be finite -- the corporations have found a way around this and simply regularly increased the copyright's term, trying to make it [de-facto](de_facto.md) [infinite](infinity.md). Their reason, of course, was to firstly forever keep ownership of their own art but also, maybe more importantly, to **kill the [public domain](public_domain.md)**, i.e. prevent old works from entering the public domain where they would become a completely free, unrestricted work for all people, competing with their proprietary art. Nowadays, with coprporations such as [YouTube](youtube.md) and [Facebook](facebook.md) de-facto controlling most of infromation sharing among common people, the situation worsens further: they can simply make their own laws that don't need to be passed by the government but simply implemented on the platform they control. This way they are already killing e.g. the right to [fair use](fair_use.md), they can simply remove any content on the basis of "copyright violation", even if such content would normally NOT violate copyright because it would fall under fair use. This would normally have to be decided by court, but a corporation here itself takes the role of the court. So in terms of copyright, corporations have now a greater say than governments, and of course they'll use this power against the people (e.g. to implement censorship and surveillance).
|
||||
The book *Free Culture* by Lessig talks, besides others, about how copyright has started and how it's been shaped by corporations to becoming their tool for monopolizing art. The concept of copyright has appeared after the invention of [printing press](printing_press.md). The so called *Statute of Anne* of 1710 allowed the authors of books to control their copying for **14 years** and only after **registartion**. The term could be prolonged by anothert 14 years if the author survived. The laws started to get more and more strict as control of information became more valued and eventually the term grew to **life of author plus 70 years**, without any need for registration or deposit of the copy of the work. Furthermore with new technologies, the scope of copyright has also extended: if copyright originally only limited *copying* of books, in the Internet age it started to cover basically any use, as any manipulation of [digital](digital.md) data in the computer age requires making local copies. Additionally the copyright laws were passing despite being unconstitutional as the US constitution says that copyright term has to be finite -- the corporations have found a way around this and simply regularly increased the copyright's term, trying to make it [de-facto](de_facto.md) [infinite](infinity.md) (technically not infinite but ever increasing). Their reason, of course, was to firstly forever keep ownership of their own art but also, maybe more importantly, to **kill the [public domain](public_domain.md)**, i.e. prevent old works from entering the public domain where they would become a completely free, unrestricted work for all people, competing with their [proprietary](proprietary.md) art (who would pay for movies if there were thousands of movies available for free?). Nowadays, with coprporations such as [YouTube](youtube.md) and [Facebook](facebook.md) de-facto controlling most of infromation sharing among common people, the situation worsens further: they can simply make their own laws that don't need to be passed by the government but simply implemented on the platform they control. This way they are already killing e.g. the right to [fair use](fair_use.md), they can simply remove any content on the basis of "copyright violation", even if such content would normally NOT violate copyright because it would fall under fair use. This would normally have to be decided by court, but a corporation here itself takes the role of the court. So in terms of copyright, corporations have now a greater say than governments, and of course they'll use this power against the people (e.g. to implement censorship and surveillance).
|
||||
|
||||
Copyright rules differ greatly by country, most notably the US measures copyright length from the publication of the work rather than from when the author died. It is possible for a work to be copyrighted in one country and not copyrighted in another. It is sometimes also very difficult to say whether a work is copyrighted because the rules have been greatly changing (e.g. a notice used to be required for some time), sometimes even retroactively copyrighting public domain works, and there also exists no official database of copyrighted works (you can't safely look up whether your creation is too similar to someone else's). All in all, copyright is a huge mess, which is why we choose [free licenses](free_software.md) and even [public domain](public_domain.md) waivers.
|
||||
|
||||
[Copyleft](copyleft.md) (also share-alike) is a concept standing against copyright, a kind of anti-copyright, invented by [Richard Stallman](rms.md) in the context of [free software](free_software.md). It's a license that grants people the rights to the author's work on the condition that they share its further modification under the same terms, which basically hacks copyright to effectively spread free works like a "virus".
|
||||
[Copyleft](copyleft.md) (also share-alike) is a concept standing against copyright, a kind of anti-copyright, invented by [Richard Stallman](rms.md) in the context of [free software](free_software.md). It's a license that grants people the rights to the author's work on the condition that they share its further modification under the same terms, which basically [hacks](hacking.md) copyright to effectively spread free works like a "virus".
|
||||
|
||||
Copyright does **not** apply to facts (including mathematical formulas) (even though the formulation of them may be copyrighted), ideas (though these may be covered by [patents](patent.md)) and single words or short phrases (these may however still be [trademarked](trademark.md)). As such copyright can't e.g. be applied to game mechanics of a computer [game](game.md) (it's an idea). It is also basically proven that copyright doesn't cover [computer languages](programming_language.md) (Oracle vs Google). Also even though many try to claim so, copyright does NOT arise for the effort needed to create the work -- so called "sweat of the brow" -- some say that when it took a great effort to create something, the author should get a copyright on it, however this is NOT and must NOT be the case (otherwise it would be possible to copyright mere ideas, simple mathematical formulas, rules of games etc.). Depending on time and location there also exist various peculiar exceptions such as the freedom of panorama for photographs or uncopyrightable utilitarian design (e.g. no one can own the shape of a generic car). But it's never good to rely on these peculiarities as they are specific to time/location, they are often highly subjective, fuzzy and debatable and may even be retroactively changed by law. This constitutes a huge legal [bloat](bloat.md) and many time legal unsafety. Do not stay in the gray area, try to stay safely far away from the fuzzy copyright line.
|
||||
Copyright does **not** (or at least should not) apply to facts (including mathematical formulas) (even though the formulation of them may be copyrighted), ideas (though these may be covered by [patents](patent.md)) and single words or short phrases (these may however still be [trademarked](trademark.md)) and similarly trivial works. As such copyright can't e.g. be applied to game mechanics of a computer [game](game.md) (it's an idea). It is also basically proven that copyright doesn't cover [computer languages](programming_language.md) (Oracle vs Google). Also even though many try to claim so, copyright does NOT arise for the effort needed to create the work -- so called "sweat of the brow" -- some say that when it took a great effort to create something, the author should get a copyright on it, however this is NOT and must NOT be the case (otherwise it would be possible to copyright mere ideas, simple mathematical formulas, rules of games etc.). Depending on time and location there also exist various peculiar exceptions such as the freedom of panorama for photographs or uncopyrightable utilitarian design (e.g. no one can own the shape of a generic car). But it's never good to rely on these peculiarities as they are specific to time/location, they are often highly subjective, fuzzy and debatable and may even be retroactively changed by law. This constitutes a huge legal [bloat](bloat.md) and many time legal unsafety. Do not stay in the gray area, try to stay safely far away from the fuzzy copyright line.
|
||||
|
||||
A work which is not covered by copyright (and any other IP) -- which is nowadays pretty rare due to the extent and duration of copyright -- is in the **[public domain](public_domain.md)**.
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ A great many commonly used tricks in programming could be regarded as hacks even
|
|||
- **[bit hacks](bit_hack.md)**: Clever manipulations of [bits](bit.md) -- for example it is possible to swap two variable without a temporary variables by using the [xor](xor.md) function. Another simplest example is implementing division by 2 as binary shift by 1 (this hack is used in real life by people for quickly dividing by 10, we just remove the last digit).
|
||||
- **[copyleft](copyleft.md)**: A legal hack by [Richard Stallman](rms.md), connected to [free software](free_software.md), working on the basis of the following idea: "If [copyright](copyright.md) lets me put any conditions on my work, I may impose a condition on my work that says that any modified version must not impose any restrictive conditions".
|
||||
- **[fast inverse square root](fast_inverse_sqrt.md)**: Famous hack that was used in the [game](game.md) Quake, it [approxmates](approximation.md) a [square root](sqrt.md) of a [floating point](float.md) number by treating it as an integer and bashing it with a [magic constant](magic_constant.md), which is about four times faster than computing the value with the obvious floating point division.
|
||||
- **Memory [rape](rape.md) in [C](c.md)**: E.g. instead of doing proper memory allocation with potentially inefficient and bloated `malloc` one may try to do a custom memory allocation without any libraries by abusing allocation on stack -- allocate a variable size array in main, set some global pointer to it and then manage this chunk of memory with your own allocation functions.
|
||||
- **[game of life](game_of_life.md) patterns**: Stable patterns such as glider or even programming game of life in game of life is a nice example of game hacking -- in fact exactly game of life hacking stood at the beginning of hacker culture.
|
||||
- **[bytebeat](bytebeat.md)**: A [demoscene](demoscene.md) hack that utilizes integer [overflows](overflow.md) to create rhythm and produce music.
|
||||
- Computer [graphics](graphics.md) uses many clever tricks that could possibly be called hacks, e.g. in times when 3D graphics was primitive and didn't allow achieving such effects as mirror reflections easily, some [games](game.md) faked mirrors simply with a hole in the wall behind which the whole mirrored room was placed -- this achieved the same effect as a mirror and didn't require any extra rendering passes or shaders.
|
||||
|
|
7
harry_potter.md
Normal file
7
harry_potter.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Harry Potter
|
||||
|
||||
Harry Potter is a [franchise](franchise.md) and universe by an English female writer J. K. Rowling about wizards and magic { like ACTUAL [wizards](wizard.md) and [magic](magic.md). ~drummyfish } that started in 1997 as an immensely successful series of seven children and young adult books, was followed by movies and later on by many other spinoff media such as video [games](game.md). It made J. K. Rowling a billionaire and has become the most famous and successful book series of modern age. At first the books sparked controversies and opposition in religious communities for "promoting witchcraft", in recent years the universe and stories have become a subject of wider political analysis and fights, as most other things.
|
||||
|
||||
{ The books are actually good -- not the best in the world, I've read many better ones that would better deserve this kind of attention, but still the work is admirable. There is of course tons of money in the franchise so it's getting raped and milked like any other IP capital -- this is of course spoiling and killing the work, so be careful. ~drummyfish }
|
||||
|
||||
**Plot summary**: sorry, we're not writing a plot summary here, thank [copyright](copyright.md) laws -- yes, [fair use](fair_use.md) allows us to do it but it would make us [non free](free_culture.md) :) Let's just say the story revolves around a boy named Harry Potter who goes to a wizard school with two friends and they're together *saving the world* from Lord Voldemort, the wizard equivalent of [Hitler](hitler.md). Overall the books start on a very light note and get progressively darker and more adult, turning into a story about "World War II but with wizards'n'magic". It's pretty readable, with great, unique atmosphere, pleasant coziness and elements of many literary genres, there's nice humor and good ideas. Also the lore is very deep.
|
81
memory_management.md
Normal file
81
memory_management.md
Normal file
|
@ -0,0 +1,81 @@
|
|||
# Memory Management
|
||||
|
||||
In [programming](programming.md) *memory management* is (unsurprisingly) the act and various techniques of managing the working [memory](memory.md) ([RAM](ram.md)) of a computer, i.e. for example dividing the total physically available memory among multiple memory users such as operating system processes and assuring they don't illegally access each other's part of memory. The scope of the term may differ depending on context, but tasks falling under memory management may include e.g. memory [allocation](allocation.md) (finding and assigning blocks of free memory) and deallocation (freeing such blocks), ensuring [memory safety](memory_safety.md), organizing blocks of memory and [optimizing](optimization.md) memory access (e.g. with [caches](cache.md) or data reorganization), [memory virtualization](virtual_memory.md) and related tasks such as address translation, handling out-of-memory [exceptions](exception.md) etc.
|
||||
|
||||
Memory management can be handled at different levels: hardware units such as the [MMU](mmu.md) and CPU [caches](cache.md) exist to perform certain time-critical memory-related tasks (such as address translation) quickly, [operating system](os.md) may help with memory management (e.g. implement virtual memory and offer [syscalls](syscall.md) for dynamic allocation and deallocation of memory), a [programming language](programming_language.md) may do some automatic memory management (e.g. [garbage collection](garbage_collection.md) or handling call stack) and programmer himself may do his own memory management (e.g. deciding between static and dynamic allocation or choosing the size of dynamic allocation chunk).
|
||||
|
||||
**Why all this fuzz?** As a newbie programmer who only works with simple variables and high level languages like [Python](python.md) that do everything for you you don't need to do much memory management yourself, but when working with data whose size may wildly differ and is not known in advance (e.g. files), someone has to handle e.g. the possibility of the data on disk not being able to fit to RAM currently allocated for your program, or -- if the data fits -- there may not be a big enough continuous chunk of memory for it. If we don't know how much memory a process will need, how much memory do we give it (too little and it may not be enough, too much and there will not be enough memory for others)? Someone has to prevent [memory leaks](memory_leak.md) so that your computer doesn't run out of memory due to [bugs](bug.md) in programs. With many [processes](process.md) running [simultaneously](multitasking.md) on a computer someone has to keep track of which process uses which part of memory and ensure [collisions](collision.md) (one process overwriting another processe's memory) don't happen, and someone needs to make sure that if bad things happen (such as process trying to write to a memory that doesn't belong to it), they don't have catastrophic consequences like [crashing](crash.md) or exploding the system.
|
||||
|
||||
## Memory Management In C
|
||||
|
||||
In [C](c.md) -- a [low level](low_level.md) language -- you need to do a lot of **manual** memory management and there is a **big danger of fucking up**, especially with dynamic allocation -- C won't hold your hand (but as a reward your program will be fast and efficient), there is no uber memory safety. There is no automatic [garbage collection](garbage_collection.md), i.e. if you allocate memory dynamically, YOU need to keep track of it and manually free it once you're done using it, or you'll end up with [memory leak](memory_leak.md).
|
||||
|
||||
For start let's see which kinds of allocation (and their associated parts of memory) there are in C:
|
||||
|
||||
- **static allocation (code/data memory)**: Simplest kind of allocation happening at compile time: if the compiler can do so (i.e. if it knows enough things such as the size of the data in advance), it allocates space of concrete size at some specific address in the part of memory reserved for code or static data (code and data may be in the same or separate parts depending on platform, see e.g. [Harvard architecture](harvard.md)) -- this is straightforward, simple, automatic and poses no real dangers, bloat or burden of dependencies. This kind of allocation applies to:
|
||||
- **global variables** (variables declared outside any function, i.e. even outside `main`)
|
||||
- **static variables** (variables inside functions declared with `static` keyword)
|
||||
- **constants/literals** (i.e. concrete numbers/strings in the source code such as `123` or `"abc"`)
|
||||
- **automatic allocation (stack memory)**: For local variables (variables inside functions) the memory is allocated in a special part of memory known as **call [stack](stack.md)** only at the time when the function is actually called and executed; i.e. this is similar to dynamic allocation (it happens at run time) but happens automatically, without needing any libraries or other explicit actions from the programmer. I.e. when a function is called at run time, a new *call frame* is created on stack which includes space for local variables of that function (along with e.g. return address from the function etc.). This is necessary e.g. to allow [recursion](recursion.md) (during which several instances of the same functions may be active, each of which may have different values of its variables), and it also helps consume less RAM. This allows for creating variable sized arrays inside functions (e.g. `int array[x];` where `x` is variable) which is not possible to do with a global array (however variable size arrays aren't supported in old ANSI C!). The disadvantage over dynamic allocation is that stack memory is relatively small and overusing it may easily cause stack [overflow](overflow.md) (running out of memory). Still this kind of allocation is better than dynamic allocation as it doesn't need any libraries, it doesn't generate complex code and the only danger is that of stack overflow -- memory leaks can't happen (deallocation happens automatically when function is exited). Automatic allocation applies to:
|
||||
- **local variables** (including function arguments and local **variable size arrays**)
|
||||
- **dynamic allocation (heap memory)**: A kind of more complex manual allocation that happens at run time and is initiated by the programmer calling special functions such as `malloc` from the `stdlib` standard library, which return [pointers](pointer.md) to the allocated memory. This memory is taken from a special part of memory known as **[heap](heap.md)**. This allows to allocate, resize and deallocate potentially very big parts of memory, but requires caution as working with pointers is involved and there is a danger of **memory leaks** -- it is the responsibility of the programmer to free allocated memory with the `free` function once it is no longer needed, otherwise that memory will simply remain allocated and unusable by others (if this happens for example in a loop, the program may just start eating up more and more RAM and eventually run out of memory). Dynamic allocation is also pretty complex (it usually involves communicating with operating system and also keeping track of the structure of memory) and creates a [dependency](dependency.md) on the `stdlib` library. Some implementations of the allocation functions are also infamously slow (up to the point of some programmers resorting to program their own dynamic allocation systems). Therefore only use dynamic allocation when absolutely necessary! Dynamic allocation applies to:
|
||||
- **memory allocated with special functions** (`malloc`, `calloc`, `realloc`)
|
||||
|
||||
Rule of the thumb: use the simplest thing possible, i.e. static allocation if you can, if not then automatic and only as the last option resort to dynamic allocation. The good news is that **you mostly won't need dynamic allocation** -- you basically only need it when working with data whose size can potentially be VERY big and is unknown at compile time (e.g. you need to load a WHOLE file AT ONCE which may potentially be VERY big). In other cases you can get away with static allocation (just reserving some reasonable amount of memory in advance and hope the data fits, e.g. a global array such as `int myData[DATA_MAX_SIZE]`) or automatic allocation if the data is reasonably small (i.e. you just create a variable sized array inside some function that processes the data). If you end up doing dynamic allocation, be careful, but it's not THAT hard to do it right (just pay more attention) and there are tools (e.g. [valgrind](valgrind.md)) to help you find memory leaks. However by the principles of [good design](lrs.md) **you should avoid dynamic allocation** if you can, not only because of the potential for errors and worse performance, but most importantly to avoid dependencies and complexity.
|
||||
|
||||
For [pros](pro.md): you can also create your own kind of pseudo dynamic allocation in pure C if you really want to avoid using stdlib or can't use it for some reason. The idea is to allocate a big chunk of memory statically (e.g. global `unsigned char myHeap[MY_HEAP_SIZE];`) and then create functions for allocating and freeing blocks of this static memory (e.g. `myAlloc` and `myFree` with same signatures as `malloc` and `free`). This allows you to use memory more efficiently than if you just dumbly (is it a word?) preallocate everything statically, i.e. you may need less total memory; this may be useful e.g. on [embedded](embedded.md). Yet another uber [hack](hacking.md) to "improve" this may be to allocate the "personal heap" on the stack instead of statically, i.e. you create something like a global pointer `unsigned char *myHeapPointer;`, then somewhere at the beginning of `main` you compute the size `myHeapSize` and then create a local array `myHeap[myHeapSize]`, then finally set the global pointer to it as `myHeapPointer = myHeap`; the rest remains the same (your allocation function will access the heap via the global pointer). Just watch out for reinventing wheels, bugs and that you actually don't end up with a worse mess that if you took a more simple approach. Hell, you might even try to write your own garbage collection and array bound checking and whatnot, but then why just not fuck it and use an already existing abomination like [Java](java.md)? :)
|
||||
|
||||
|
||||
|
||||
|
||||
Finally let's see some simple code example:
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // needed for dynamic allocation :(
|
||||
|
||||
#define MY_DATA_MAX_SIZE 1024 // if you'll ever need more, just change this and recompile
|
||||
|
||||
unsigned char staticMemory[MY_DATA_MAX_SIZE]; // statically allocated array :)
|
||||
int simpleNumber; // this is also allocated statically :)
|
||||
|
||||
void myFunction(int x)
|
||||
{
|
||||
static int staticNumber; // this is allocated statically, NOT on stack
|
||||
int localNumber; // this is allocated on stack
|
||||
int localArray[x + 1]; // variable size array, allocated on stack, hope x isn't too big
|
||||
|
||||
localNumber = 2 * x; // do something with the memory
|
||||
localArray[x] = localNumber;
|
||||
|
||||
if (x > 0) // recursively call the function
|
||||
myFunction(x - 1);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int localNumberInMain = 123; // this is also allocated on stack
|
||||
|
||||
myFunction(10); // change to 10000000 to see a probable stack overflow
|
||||
|
||||
for (int i = 0; i < 200000; ++i)
|
||||
{
|
||||
if (i % 1000 == 0)
|
||||
printf("i = %d\n",i);
|
||||
|
||||
unsigned char *dynamicMemory = (char *) malloc((i + 1) * 10000); // oh no, dynamic allocation, BLOAAAT!
|
||||
|
||||
if (!dynamicMemory)
|
||||
{
|
||||
printf("Couldn't allocate memory, there's probably not enough of it :/");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dynamicMemory[i * 128] = 123; // do something with the memory
|
||||
|
||||
free(dynamicMemory); // if not done, memory leak occurs! try to remove this and see :)
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
|
@ -12,7 +12,7 @@ Pedophilia is a sexual orientation towards children. Pedophiles are often called
|
|||
|
||||
Unlike for example pure [homosexuality](gay.md), pedophilia is completely natural, normal and not any more harmful than any other orientation, however it is nowadays wrongfully, for political reasons, labelled a "disorder" (just as homosexuality used to be not a long time ago). It is the forbidden, tabooed, censored and bullied sexual orientation of the [21st century](21st_century.md), even though all healthy people are pedophiles -- just don't pretend you've never seen a [jailbait](jailbait.md) you found sexy, people start being sexually attractive exactly as soon as they become able to reproduce; furthermore when you've gone without sex long enough and get extremely horny, you get turned on by anything that literally has some kind of hole in it -- this is completely normal. Basically everyone has some kind of weird fetish he hides from the world, there are people who literally fuck cars in their exhausts, people who like to eat shit, dress in diapers and hang from ceiling by their nipples, people who have sexual relationships with virtual characters etc. -- this is all considered normal, but somehow once you get an erection seeing a hot 17 year old girl, you're a demon that needs to be locked up and cured, if not executed right away, just for a thought present in your mind.
|
||||
|
||||
Even though one cannot choose this orientation and even though pedophiles don't hurt anyone any more than for example gay people do, they are highly oppressed and tortured. Despite what the propaganda says, a **pedophile is not automatically a rapist** of children (a pedophile will probably choose to never actually even have sex with a child) any more than a gay man is automatically a rapist of people of the same sex, and watching [child porn](child_porn.md) won't make you want to rape children any more than watching gay porn will make you want to rape people of the same sex. Nevertheless the society, especially the fascists from the [LGBT](lgbt.md) movement who ought to know better than anyone else what it is like to be oppressed only because of private sexual desires, actively hunt pedophiles, [bully](cancel_culture.md) them and lynch them on the Internet and in the [real life](irl.md) -- this is done by both both civilians and the state (I shit you not, in [Murica](usa.md) there are whole police teams of pink haired lesbians who pretend to be little girls on the Internet and tease guys so that they can lock them up and get a medal for it). There is a literal **witch hunt** going on against completely innocent people, just like in the middle ages. Innocent people are tortured, castrated, cancelled, rid of their careers, imprisoned, beaten, rid of their friends and families and pushed to suicide sometimes only for having certain files on their computers or saying something inappropriate online (not that any of the above is ever justified to do to anyone, even the worst criminal).
|
||||
Even though one cannot choose this orientation and even though pedophiles don't hurt anyone any more than for example gay people do, they are highly oppressed and tortured. Despite what the propaganda says, a **pedophile is not automatically a rapist** of children (a pedophile will probably choose to never actually even have sex with a child) any more than a gay man is automatically a rapist of people of the same sex, and watching [child porn](child_porn.md) won't make you want to rape children any more than watching gay porn will make you want to rape people of the same sex. Nevertheless the society, especially the fascists from the [LGBT](lgbt.md) movement who ought to know better than anyone else what it is like to be oppressed only because of private sexual desires, actively hunt pedophiles, [bully](cancel_culture.md) them and lynch them on the Internet and in the [real life](irl.md) -- this is done by both both civilians and the state (I shit you not, in [Murica](usa.md) there are whole police teams of pink haired lesbians who pretend to be little girls on the Internet and tease guys so that they can lock them up and get a medal for it). LGBT activists proclaim that a "child can't consent" but at the same time tell you that "a prepubescent child can make a decision about changing its sex" (yes, it's happening, even if parent's agreement is also needed, would parents also be able to allow a child to have sex if it wishes to?). There is a literal **witch hunt** going on against completely innocent people, just like in the middle ages. Innocent people are tortured, castrated, cancelled, rid of their careers, imprisoned, beaten, rid of their friends and families and pushed to suicide sometimes only for having certain files on their computers or saying something inappropriate online (not that any of the above is ever justified to do to anyone, even the worst criminal).
|
||||
|
||||
The fact that they made people believe it is a disorder if your penis can't magically telepathically check a chick's ID and may get erect if she's been born before a date legally established in political region the penis currently resides in shows that at this point an average citizen is more retarded than a braindead chimp.
|
||||
|
||||
|
|
11
plan9.md
Normal file
11
plan9.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Plan 9
|
||||
|
||||
Plan 9 (from Bell Labs, reference to the movie *Plan 9 from Outer Space*) is a research [operating system](os.md), now [FOSS](foss.md), that was started by many of the original [Unix](unix.md) developers as the next project of this kind, i.e. kind of a "new and updated Unix". It works with [Unix philosophy](unix_philosophy.md) ([minimalist](minimalism.md) software philosophy) but tries to expand and modify it so as to fit "new/evolved" [computers](computer.md) -- though Plan 9 developers claim the system is "more Unix than Unix itself", the validity of such claim is questionable as Plan 9 brings in a more complicated paradigm of [distributed computing](distributed_computing.md), [dependencies](dependency.md) (such as requiring [GUI](gui.md) and mouse) and therefore [bloat](bloat.md) (though still being super minimal compared to mainstream operating systems). Besides the original Plan 9, which is apparently dead now, there exist active [forks](fork.md) such as 9front.
|
||||
|
||||
On one hand Plan 9 sounds good and its idealism is admirable, nevertheless **Plan 9 is [SHIT](shit.md)** due to the following fact: **it [requires](dependency.md) what isn't necessary, for example [GUI](gui.md), [mouse](mouse.md), file system and networking** and **forces computers and users to be certain way**. This is absolutely unforgivable and violates the basic premise of [good, freedom offering, minimalist nondiscriminatory software](lrs.md); in fact it violates the [Unix philosophy](unix_philosophy.md) which it is supposed to be building on top of -- an operating system should do one thing well: that of offering and environment for programs and their resources, user interface is a nontrivial extra task that should be separated. If you ask how to use Plan 9 without a mouse, the fans respond with telling you how stupid you are for not wanting to use mouse ("here is a study that says mice are better than keyboards: checkmate!") and that using mouse is actually what you want (hey bro, everyone's using a mouse, just accept it) -- they try to force a specific way of how computers should be and how they should be operated, just as [Microsoft](microsoft.md) and [Apple](apple.md), without taking into account that computers can (and should be allowed to) be wildly different, very small, with tiny displays (or no displays at all), with no pointing devices (game consoles, voice operated computers, ...) etc. Sure, it may be possible to make the system work without a mouse or GUI, but these concepts form the very basis of the code and its philosophy, they will be carried as a dead weight if you're not using them and you will probably encounter great issues such as many programs simply relying on the existence of GUI and mouse and not working without them. The philosophy is similar to that of "[smart](smart.md)" devices which assume that "Internet is everywhere" and so "let's put Internet into everything", even things that don't need any Internet at all (like hammers and teaspoons), and by the way they will no longer work without Internet (let's hope it doesn't go down lol). In this way **Plan 9 is a dictatorship** and [we](lrs.md) don't approve of it.
|
||||
|
||||
{ To plan 9 fans: please let me know if I misunderstand the the concepts somehow, but this is how I understand the system. Beware however that trying to convince me to simply conform with your way of computing will lead nowhere. ~drummyfish }
|
||||
|
||||
Plan9's mascot, Glenda, is **[proprietary](proprietary.md)** (as of february 2023), despite it having been uploaded to Wikimedia Commons lol. No license to be seen on its website.
|
||||
|
||||
TODO: some more shite like history and the actual basic concepts?
|
Loading…
Reference in a new issue