Skip to content

Commit a847fbf

Browse files
committed
Converting html style images in markdown into markdown format
1 parent f38f579 commit a847fbf

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

chapters/memory/chapter.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Internally the computer doens't really now about that memory area as `i` but as
3737

3838
When we create a variable like `int i` we are telling our program to reserve 4 bytes of memory, associate the address of the first byte of those 4 to the variable name `i` and restrict the type of data that we are going to store in those 4 bytes to only ints.
3939

40-
<img src="images/int_i.svg" height="300"/>
40+
![Int i](images/int_i.svg "")
4141

4242
Usually memory addresses are represented in [hexadecimal](http://en.wikipedia.org/wiki/Hexadecimal). In c++ you can get the memory address of a variable by using the `&` operator, like:
4343

@@ -55,7 +55,7 @@ i = 0;
5555

5656
Our memory will look like:
5757

58-
<img src="images/int_i_equals_0.svg" height="300"/>
58+
![Int i equals 0](images/int_i_equals_0.svg "")
5959

6060
The order in which the bytes that form the int are layed out in the memory depends on the architecture of our computer, you'll prpbably seen [little endian and big endian](http://en.wikipedia.org/wiki/Endianness) mentioned sometime. Those terms refer to how the bytes of a data type are ordered in memory, if the most significative bytes come first or last. Most of the time we don't really need to know about this order but most modern computer architectures use little endian.
6161

@@ -156,7 +156,7 @@ int * p = &i;
156156

157157
And what we get in memory is something like:
158158

159-
<img src="images/pointer.svg" height="300"/>
159+
![Pointer](images/pointer.svg "")
160160

161161
A pointer usually occupies 4/8 bytes (depending if we are on a 32 or 64bits application), we are representing it as 1 byte only to make things easier to understand, but as you can see it's just another variable, that instead of containing a value contains a memory address that points to a value. That's why it's called pointer.
162162

@@ -169,7 +169,7 @@ int i;
169169
```
170170
We get a memory layout like:
171171

172-
<img src="images/int_i.svg" height="300"/>
172+
![Int i](images/int_i.svg "")
173173

174174
As we see there's no value in that memory area yet. In other languages like processing doing something like:
175175

@@ -278,7 +278,7 @@ In both languages the `=` means copy the value of the right side into the variab
278278

279279
This is more or less what memory would look like in Java and C++:
280280

281-
<img src="images/objects_java_c.svg" height="300"/>
281+
![Objects Java C](images/objects_java_c.svg "")
282282

283283
As you can see in c++ objects in memory are just all their member variables one after another. When we make an object variable equal to another, by default, c++ copies all the object to the left side of the equal operator.
284284

@@ -309,8 +309,7 @@ p2 = p1;
309309

310310
Well as before c++ will copy the contents of p1 on p2, the contents of p1 are an ofVec2f which consits of 2 floats x and y and then a pointer to a ParticleSystem, and that'w what gets copied, the ParticleSystem itself won't get copied only the pointer to it, so p2 will end up having a copy of the position of p2 and a pointer to the same ParticleSystem but we'll have only 1 particle system.
311311

312-
313-
<img src="images/object_pointers.svg" height="300"/>
312+
![Object pointers](images/object_pointers.svg "")
314313

315314
The fact that things are copied by default and that objects can be stored in the stack as oposed to being always a pointer has certain adavantages. For example, in c++ a vector or an array of particles like the ones we've used in the last example will look like:
316315

@@ -619,7 +618,7 @@ most probably our application will crash if the memory address at arr + 25 is ou
619618

620619
We've just sayd arr + 25? what does that mean? As we've seen before a variable is just some place in memmory, we can get it's memory address which is the first byte that is asigned to that variable in memory. With arrays is pretty much the same, for example since we know that an int occupies 4 bytes in memory, an array of 10 ints will occupy 40 bytes and those bytes are contiguous:
621620

622-
<img src="images/array.svg" height="300"/>
621+
![Array](images/array.svg "")
623622

624623
Remember that memory addresses are expressed as hexadecimal so 40 == 0x0028. Now to take the address of an array, as with other variable we might want to use the `&` operator and indeed we can do it like:
625624

@@ -752,13 +751,13 @@ Vectors have some more features and using them properly might be tricky mostly i
752751

753752
Having objects in memory one after another is most of the time what we want, the access is really fast no matter if we want to access sequentially to each of them or randomly to anyone, since a vector is just an array internally, accesing let's say position 20 in it, just means that internally it just needs to get the memory address of the first position and add 20 to it. In soime cases though, vectors are not the most optimal memory structure. For example, if we want to frequnetly add or remove elements in the middle of the vector, and you imagine the vector as a memory strip, that means that we need to move the rest of the vector till the end one position to the right and then insert the new element in the free location. In memory there's no such thing as move, moving contiguous memory means copying it and as we've said before, copying memory is a relatively slow operation.
754753

755-
<img src="images/vector_inserting.svg" height="300"/>
754+
![Vector inserting](images/vector_inserting.svg "")
756755

757756
Sometimes, if there's not enough memory to move/copy the elements, one position to the right, the vector will need to copy the whole thing to a new memory location. If we are working with thousands of elements and doing this very frequently, like for example every frame, this can really slow things down a lot.
758757

759758
To solve that, there's other memory structures like for example lists. In a list, memory, is not contiguous but instead each element has a pointer to the next and previous element so inserting one element just means changing those pointers to point to the newly added element. In a list we never need to move elements around but it's main disadvantage is that not being the elements contiguous in memory it's access can be slightly slower than a vector, also that we can't use it in certain cases like for example to upload data to the graphics card which always wants contiguos memory.
760759

761-
<img src="images/list.svg" height="300"/>
760+
![List](images/list.svg "")
762761

763762
Another problem of lists is that trying to access an element in the middle of the list (what is called random access) is slow since we always have to go through all the list till we arrive to the desired element. Lists are used then, when we seldom need to access randomly to a position of it and we need to add or remove elements in the middle frequently. For the specifics of the syntax of a list you can check the [c++ documentation on lists](http://www.cplusplus.com/reference/list/list/)
764763

chapters/threads/chapter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ This way the loading of the image happens simultaneously to our update/draw loop
5656
5757
Now, how do we know when our image is loaded? The thread will run separately from the main thread of our application:
5858
59-
<img src="images/simple_thread.svg" height="300"/>
59+
![Simple Thread](images/simple_thread.svg "Simple Thread")
6060
6161
As we see in the image the duration of loading of the image and thus the duration of the call to threadedFunction is not automatically known to the main thread. Since all our thread does is load the image, we can check if the thread has finished running which will tell us that the image has loaded. For that ofThread has a method: `isThreadRunning()`:
6262

0 commit comments

Comments
 (0)