aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eleventy.config.js3
-rw-r--r--includes/base.html3
-rw-r--r--includes/main.css150
-rw-r--r--package-lock.json3
-rw-r--r--package.json3
-rw-r--r--src/posts/primer-on-memory-management/index.md48
6 files changed, 180 insertions, 30 deletions
diff --git a/eleventy.config.js b/eleventy.config.js
index 049294f..5f804a6 100644
--- a/eleventy.config.js
+++ b/eleventy.config.js
@@ -17,7 +17,6 @@ import mdContainer from 'markdown-it-container';
import postcss from 'postcss';
import cssnano from 'cssnano';
-
import metadata from './data/metadata.js';
@@ -60,7 +59,7 @@ export default async function(eleventyConfig) {
removeAll: true,
},
}]
- })
+ }),
]).process(content, {
from: this.page.inputPath,
to: null,
diff --git a/includes/base.html b/includes/base.html
index 27c13cb..7aabdf5 100644
--- a/includes/base.html
+++ b/includes/base.html
@@ -23,7 +23,6 @@
<meta name="twitter:card" content="summary">
<link rel="alternate" href="/atom.xml" type="application/atom+xml" :title="metadata.title">
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
- <link rel="stylesheet" href="../node_modules/prismjs/themes/prism-okaidia.css" />
<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" :href="getBundleFileUrl('css')" webc:keep />
</head>
@@ -35,7 +34,7 @@
<template webc:for="entry of eleventyNavigation(collections.all)" webc:nokeep>
<a :href="entry.url" @text="entry.title"></a>
</template>
- <a :href="https://git.sudomsg.com/">Git</a>
+ <a href="https://git.sudomsg.com/">Git</a>
</nav>
</header>
<main @html="content"></main>
diff --git a/includes/main.css b/includes/main.css
index 92fcf5c..b618b5a 100644
--- a/includes/main.css
+++ b/includes/main.css
@@ -37,9 +37,14 @@ canvas,
audio,
iframe,
embed,
+table,
+pre[class*="language-"],
object {
- max-inline-size: 100%;
display: block;
+ margin-left: auto;
+ margin-right: auto;
+ width: fit-content;
+ max-width: 90%;
}
h1 {
@@ -68,6 +73,111 @@ td {
border: 1px solid;
}
+th,
+td {
+ padding: 1rem;
+}
+
+th {
+ background: darkred;
+ color: white;
+}
+
+code {
+ font-size: 0.9rem;
+ font-family: monospace;
+}
+
+code[class*="language-"],
+pre[class*="language-"] {
+ line-height: 1.5;
+ white-space: pre;
+}
+
+pre[class*="language-"] {
+ border: solid;
+ padding: 1rem;
+ border-radius: 0.25rem;
+ min-width: 70%;
+}
+
+.token {
+ &:is(.comment, .prolog, .doctype, .cdata) {
+ color: darkgreen;
+ font-style: italic;
+
+ @media (prefers-color-scheme: dark) {
+ color: lightgreen;
+ }
+ }
+
+ &.punctuation {
+ color: dimgray;
+
+ @media (prefers-color-scheme: dark) {
+ color: lightgray;
+ }
+ }
+
+ &:is(.property, .tag, .constant, .symbol, .deleted) {
+ color: firebrick;
+
+ @media (prefers-color-scheme: dark) {
+ color: lightgray;
+ }
+ }
+
+ &:is(.boolean, .number) {
+ color: teal;
+
+ @media (prefers-color-scheme: dark) {
+ color: cyan;
+ }
+ }
+
+ &:is(.selector, .attr-name, .string, .char, .builtin, .inserted) {
+ color: saddlebrown;
+
+ @media (prefers-color-scheme: dark) {
+ color: wheat;
+ }
+ }
+
+ &:is(.operator, .entity, .url, .variable) {
+ color: darkmagenta;
+
+ @media (prefers-color-scheme: dark) {
+ color: orchid;
+ }
+ }
+
+ &:is(.atrule, .attr-value, .keyword) {
+ color: darkred;
+ font-weight: bold;
+
+ @media (prefers-color-scheme: dark) {
+ color: tomato;
+ }
+ }
+
+ &:is(.function, .class-name) {
+ color: mediumblue;
+ font-weight: bold;
+
+ @media (prefers-color-scheme: dark) {
+ color: dodgerblue;
+ }
+ }
+
+ &:is(.regex, .important) {
+ color: chocolate;
+
+ @media (prefers-color-scheme: dark) {
+ color: goldenrod;
+ }
+ }
+}
+
@media screen {
* :any-link:hover,
@@ -129,12 +239,16 @@ td {
border: 2px solid;
}
+ th,
aside {
border: 2px solid;
}
}
@media print {
+ * {
+ print-color-adjust: exact;
+ }
header,
footer {
@@ -151,4 +265,38 @@ td {
break-inside: avoid;
break-before: auto;
}
+
+ h2,
+ h3,
+ th {
+ page-break-after: avoid;
+ }
+
+ a[href]:after {
+ content: " <" attr(href) "> ";
+ }
+
+ abbr[title]:after {
+ content: " (" attr(title) ") ";
+ }
+
+ abbr {
+ text-decoration: none;
+ }
+
+ pre[class*="language-"] {
+ background: none;
+ color: black;
+ border: solid black;
+ box-shadow: none;
+ page-break-inside: avoid;
+ }
+
+ pre[class*="language-"] {
+ background: none;
+ color: black;
+ border: solid black;
+ box-shadow: none;
+ page-break-inside: avoid;
+ }
}
diff --git a/package-lock.json b/package-lock.json
index 6c0e2ec..7930ba2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -21,8 +21,7 @@
"luxon": "^3.6.1",
"markdown-it-abbr": "^2.0.0",
"markdown-it-container": "^4.0.0",
- "postcss": "^8.5.6",
- "prismjs": "^1.30.0"
+ "postcss": "^8.5.6"
}
},
"node_modules/@11ty/dependency-tree": {
diff --git a/package.json b/package.json
index eecfb65..d2a123b 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,6 @@
"luxon": "^3.6.1",
"markdown-it-abbr": "^2.0.0",
"markdown-it-container": "^4.0.0",
- "postcss": "^8.5.6",
- "prismjs": "^1.30.0"
+ "postcss": "^8.5.6"
}
}
diff --git a/src/posts/primer-on-memory-management/index.md b/src/posts/primer-on-memory-management/index.md
index 5e41448..41e79f5 100644
--- a/src/posts/primer-on-memory-management/index.md
+++ b/src/posts/primer-on-memory-management/index.md
@@ -61,6 +61,8 @@ struct data {
};
```
+Which creates an object of the following layout in memory:
+
Offset | Content
-------|-----------------------
0x0000 | char character (1B)
@@ -103,14 +105,14 @@ The assembly output on x86_64:
``` nasm
a:
- push rbp
- mov rbp, rsp
- lea rsi, [rbp + 16]
- lea rdi, [rip + b]
- mov edx, 65536 ;; also this is assignment in x86
- call memcpy@PLT ;; notice the memcpy
- pop rbp
- ret
+ push rbp
+ mov rbp, rsp
+ lea rsi, [rbp + 16]
+ lea rdi, [rip + b]
+ mov edx, 65536 ;; also this is assignment in x86
+ call memcpy@PLT ;; notice the memcpy
+ pop rbp
+ ret
```
## Refer and Point
@@ -251,10 +253,10 @@ with `LW` and `SW` as shown bellow for adding 2 variables.
``` asm
; int c = a + b;
- lw $1, 12($fp) ; load
- lw $2, 8($fp) ; load
- addu $1, $1, $2 ; the actual action
- sw $1, 4($fp) ; store
+ lw $1, 12($fp) ; load
+ lw $2, 8($fp) ; load
+ addu $1, $1, $2 ; the actual action
+ sw $1, 4($fp) ; store
```
Functions in compiled code are invoked via their memory address which is
@@ -302,7 +304,8 @@ neck due to fetching code and data is the same bus (not parallel).
#### Harvard Architecture
-*[JIT]: Just In Time Compilation *[ROM]: Read only Memory
+*[JIT]: Just In Time Compilation
+*[ROM]: Read only Memory
The data and code use different memory bus and therefore different addressing
space. This is common in embedded where the code is in ROM. Self-modifying and
@@ -407,7 +410,7 @@ void dealloc<typename T>(T* old){
}
```
-Observe the dealloc function or method. Its really fast but it frees any thing
+Observe the `dealloc` function or method. Its really fast but it frees any thing
allocated after it. This means that while it's good for local variables, it also
implies that the return variable of a function must be at the top of the stack
after the function returns. This means returning pointer to local variable is
@@ -438,7 +441,7 @@ Example are network sockets or widgets.
[[nodiscard]] char *bar(){
char* a = malloc(10); // request 10 bytes of heap from runtime
if (!a){
- return NULL; // malloc fails discuss later
+ return nullptr; // malloc fails discuss later
}
strcpy(a, "hello");
return a; // Will not free a
@@ -504,11 +507,11 @@ pointers.
### Out of Memory Errors
-Most Programs assume ```malloc``` will not error which is mostly true as
+Most Programs assume `malloc` will not error which is mostly true as
operating systems overcommit memory. But still either due lack of overcommit so
out of memory or other reason (such as internal fragmentation). This must be
-handled (```malloc``` returns null and exception in certain languages). Be very
-careful and never assume ```malloc``` will always return memory.
+handled (`malloc` returns null and exception in certain languages). Be very
+careful and never assume `malloc` will always return memory.
### Lifetime Errors
@@ -623,8 +626,8 @@ A method which I personally use in the case of trees is to create an object pool
(which is similar to arena but only for a single type). This simplifies clean up
of tree when done.
-*[RAII]: Resource acquisition is initialization *[OOP]: Object Oriented
-Programming
+*[RAII]: Resource acquisition is initialization
+*[OOP]: Object Oriented Programming
### RAII
@@ -640,7 +643,10 @@ reference counting.
Similar pattern for defer but this works by inserting code hooks to the end of
scope so you can call cleanup after you are done. This is in Zig.
-``` zig var list = ArrayList(u8).init(allocator); defer list.deinit(); ```
+``` zig
+var list = ArrayList(u8).init(allocator);
+defer list.deinit();
+```
Now this method is not memory management specific and ownership and lifetimes
are technically also for system resources too like files, devices, windows, etc.