master
Miloslav Ciz 2 years ago
parent ca8db11490
commit 2a3b06eb67

@ -1575,10 +1575,71 @@ Another thing to mention is that we can have **pointers to functions**; this is
## Dynamic Allocation (Malloc)
## Debugging, Optimization
Dynamic memory allocation means the possibility of reserving additional memory for our program at run time, whenever we need it. This is opposed to static memory allocation, i.e. reserving memory for use at compile time (when compiling, before the program runs). We've already been doing static allocation whenever we created a variable -- compiler automatically reserves as much memory for our variables as is needed. But what if we're writing a program but don't yet know how much memory it will need? Maybe the program will be reading a file but we don't know how big that file is going to be -- how much memory should we reserve? Dynamic allocation allows us to reserve this memory with functions when the program is actually runing and already knows how much of it should be reserved.
It must be known that dynamic allocation comes with a new kind of bug known as a **[memory leak](memory_leak.md)**. It happens when we reserve a memory and forget to free it after we no longer need it. If this happens e.g. in a loop, the program will continue to "grow", eat more and more RAM until operating system has no more to give. For this reason, as well as others such as simplicity, it may sometimes be better to go with only static allocation.
Anyway, let's see how we can allocate memory if we need to. We use mostly just two functions that are provided by the *stdlib* library. One is `malloc` which takes as an argument size of the memory we want to allocate (reserve) in bytes and returns a pointer to this allocated memory if successful or `NULL` if the memory couldn't be allocated (which in serious programs we should always check). The other function is `free` which frees the memory when we no longer need it (every allocated memory should be freed at some point) -- it takes as the only parameter a pointer to the memory we've previously allocated. There is also another function called `realloc` which serves to change the size of an already allocated memory: it takes a pointer the the allocated memory and the new size in byte, and returns the pointer to the resized memory.
Here is an example:
```
#include <stdio.h>
#include <stdlib.h>
#define ALLOCATION_CHUNK 32 // by how many bytes to resize
## Advanced Stuff
int main(void)
{
int charsRead = 0;
int resized = 0; // how many times we called realloc
char *inputChars = malloc(ALLOCATION_CHUNK * sizeof(char));
while (1) // read input characters
{
char c = getchar();
charsRead++;
if (c == '\n')
break;
if ((charsRead % ALLOCATION_CHUNK) == 0)
{
inputChars = // we need more space, resize the array
realloc(inputChars,(charsRead / ALLOCATION_CHUNK + 1) * ALLOCATION_CHUNK * sizeof(char));
resized++;
}
inputChars[charsRead] = c;
}
puts("The string you entered backwards:");
while (charsRead > 0)
{
putchar(inputChars[charsRead - 1]);
charsRead--;
}
free(inputChars); // important!
putchar('\n');
printf("I had to resize the input buffer %d times.",resized);
return 0;
}
```
This code reads characters from the input and stores them in an array (`inputChars`) -- the array is dynamically resized if more characters are needed. (We restraing from calling the array `inputChars` a string because we never terminate it with 0, we couldn't print it with standard functions like `puts`.) At the end the entered characters are printed backwards (to prove we really stored all of them), and we print out how many times we needed to resize the array.
We define a constant (macro) `ALLOCATION_CHUNK` that says by how many characters we'll be resizing our character buffer. I.e. at the beginning we create a character buffer of size `ALLOCATION_CHUNK` and start reading input character into it. Once it fills up we resize the buffer by another `ALLOCATION_CHUNK` characters and so on. We could be resizing the buffer by single characters but that's usually inefficient (the function `malloc` may be quite complex and take some time to execute).
The line starting with `char *inputChars = malloc(...` creates a pointer to `char` -- our character buffer -- to which we assign a chunk of memory allocated with `malloc`. Its size is `ALLOCATION_CHUNK * sizeof(char)`. Note that for simplicity we don't check if `inputChars` is not `NULL`, i.e. whether the allocation succeeded -- but in your program you should do it :) Then we enter the character reading loop inside which we check if the buffer has filled up (`if ((charsRead % ALLOCATION_CHUNK) == 0)`). If so, we used the `realloc` function to increase the size of the character buffer. The important thing is that once we exit the loop and print the characters stored in the buffer, we free the memory with `free(inputChars);` as we no longer need it.
## Debugging, Optimization
## Final Program
## Under The Hood
## Advanced Stuff and Where to Continue

@ -1,12 +1,12 @@
# Left Vs Right
Left and right are two basic opposing political sides that roughly come down to the pro-equality (left) and pro-hierarchy (right). There is a lot of confusion and vagueness about these terms, so let us now define these terms as used on this wiki:
Left and right are two basic opposing political sides that roughly come down to the pro-equality (left) and pro-hierarchy (right). There is a lot of confusion and vagueness about these terms, so let us now define them as used on this wiki:
- The (true) **left is pro social equality**, i.e. against social hierarchies. This includes equality of everyone, period. Note that social equality does NOT imply people being made (or being made to appear) equal in other ways, e.g. physically -- true left accepts difference between people and [races](race.md) and doesn't hide them. Even if the perfectly ideally leftist society can't be completely achieved, true left tries to get **as close to it as possible**. The values of true left are for example sharing, [love](love.md), [selflessness](selflessness.md), [altruism](altruism.md), forgiveness and nonviolence. Groups and movements that are at least highly truly leftist include [anarcho pacifism](anpac.md), [free software](free_software.md), [free culture](free_culture.md) and of course [LRS](lrs.md).
- The (true) **left is pro social equality**, i.e. against social hierarchies. This includes equality of all living beings, period. Note that social equality does NOT imply people being made (or being made to appear) equal in other ways, e.g. physically -- true left accepts difference between people and [races](race.md) and doesn't hide them. Even if the perfectly ideally leftist society can't be completely achieved, true left tries to get **as close to it as possible**. The values of true left are for example sharing, [love](love.md), [selflessness](selflessness.md), [altruism](altruism.md), forgiveness and nonviolence. Groups and movements that are at least highly truly leftist include [anarcho pacifism](anpac.md), [free software](free_software.md), [free culture](free_culture.md) and of course [LRS](lrs.md).
- The **right is pro social hierarchy**, i.e. against social equality. This means some people standing above others, be it by strength, power, wealth, social status, privileges etc. The rightist values are mostly those associated with [evil](evil.md), i.e. violence, oppression, conflict, war, revenge, survival of the fittest etc. Among rightism can be included [fascism](fascism.md), [capitalism](capitalism.md), US republican party, states, the military etc.
- The **pseudoleft** is pretending to be left while in fact being right due to e.g. using non-leftist means (such as violence) or even having non-leftist goals (e.g. benefit of specific minority as opposed to benefit of everyone). Among pseudoleftist movements are [feminism](feminism.md), [LGBT](lgbt.md), [Antifa](antifa.md) or [Marxism](marxism.md).
There exists a "theory" called a horse shoe. It says that the extremes of the left-right spectrum tend to be alike (violence, hating, radical), just as the two ends of a horse shoe. This is only an illusion caused by ignoring the existence of pseudoleft. The following diagram shows the true situation:
There exists a "theory" called a horse shoe. It says that the extremes of the left-right spectrum tend to be alike (violent, hating, radical), just as the two ends of a horse shoe. This is only an illusion caused by ignoring the existence of pseudoleft. The following diagram shows the true situation:
```
TRUE LEFT (peace, selflessness, forgiveness, ...)
@ -15,14 +15,15 @@ TRUE LEFT (peace, selflessness, forgiveness, ...)
| | <== illusion of horse shoe
| |
\ /
V V
PSEUDOLEFT RIGHT
(violence, conflict, aggressivity, ...)
```
We see pseudoleft is something that began as going away from the right but slowly turned around back to its values, just from a slightly different direction. This is because rightism is very easy, it offers tempting short-term solutions such as violence, and so it exhorts a kind of magnetic force on every human -- most cannot resist and only very few get to the true left despite this force.
What's called *left* in the [modern](modern.md) western culture usually means *pseudoleft*. The existence of pseudoleftism is often overlooked or unknown. It is a camp that falsely calls itself [leftist](left.md) while being in fact [rightist](right.md) in disguise. It used to be found mainly in the [US](us.md), however globalization spreads this [cancer](cancer.md) all over the world. Pseudoleft justifies its actions with a goal that may seem truly leftist, such as "equality", but uses means completely unacceptable by true left (which are in fact incompatible with equality), such as [violence](violence.md), bullying, lynching, [cancelling](cancel_culture.md), [censorship](censorship.md) or brainwashing. Pseudoleft is aggressive. It believes that **ends justify the means** and that **it's fine to bully a bully** ("eye for an eye"). A pseudoleftist movement naturally evolves towards shifting its goals from a leftist one such as equality towards a [fascist](fascism.md) one such as a (blind) *fight for some group's rights* (even if that group may already have achieved equality and more).
What's called *left* in the [modern](modern.md) western culture usually means *pseudoleft*. The existence of pseudoleftism is often overlooked or unknown. It used to be found mainly in the [US](us.md), however globalization spreads this [cancer](cancer.md) all over the world. Pseudoleft justifies its actions with a goal that may seem truly leftist, such as "equality", but uses means completely unacceptable by true left (which are in fact incompatible with equality), such as [violence](violence.md), bullying, lynching, [cancelling](cancel_culture.md), [censorship](censorship.md) or brainwashing. Pseudoleft is aggressive. It believes that **"ends justify the means"** and that **"it's fine to bully a bully"** ("eye for an eye"). A pseudoleftist movement naturally evolves towards shifting its goals from a leftist one such as equality towards a [fascist](fascism.md) one such as a (blind) *fight for some group's rights* (even if that group may already have achieved equality and more).
The difference between left and pseudoleft can be shown in many ways; one of them may be that pseudoleft always wants to **[fight](fight_culture.md)** something, usually the right (as they're essentially the same, i.e. natural competitiors). True left wants to end all fights. Pseudoleft invents [bullshit](bullshit.md) artificial issues such as [political correctness](political_correctness.md) that sparks conflict, as it lives by conflict. Left tries to find peace by solving problems. Pseudoleft sees it as acceptable to do bad things to people who commited something it deems bad. True left knows that violence creates violence, it "turns the other cheek", it cures hate with love.
Why is there no pseudoright? Because it doesn't make sense :) Left is good, right is a sincere evil and pseudoleft is an evil pretending to be good. A good pretending to be evil doesn't probably exist in any significant form.

@ -0,0 +1,5 @@
# Pseudominimalism
Pseudominimalism is the property of technology of trying to appear [minimalist](minimalism.md) on the surface while being [bloated](bloat.md) on the inside. A typical example could be a website that has minimal look -- a blank white background with some fancy-font text perhaps -- which in the background uses dozens of [JavaScript](js.md) frameworks and libraries and requires a high end CPU to even appear responsive. [Apple](apple.md) is heavily practicing pseudominimalism.
Another example are many [modern](modern.md) [CLI](cli.md) programs that [code monkeys](coder.md) use to impress their [YouTube](youtube.md) viewers or to feel like matrix haxors. Some people think that anything running in command line is minimalist which is less and less true as we progress into the future. A lot of [capitalist software](capitalist_software.md) add a CLI interface ex post **on top** of an already bloated program, often by simply disabling [GUI](gui.md) (but leaving all its dependencies in). An example may be the [gomux](gomux.md) chat client.

@ -2,4 +2,6 @@
TODO
Rust is [shit](shit.md).
LMAO https://github.com/mTvare6/hello-world.rs
Loading…
Cancel
Save