<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Game_Engines_2021W_Lecture_5</id>
	<title>Game Engines 2021W Lecture 5 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Game_Engines_2021W_Lecture_5"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Game_Engines_2021W_Lecture_5&amp;action=history"/>
	<updated>2026-04-08T03:15:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Game_Engines_2021W_Lecture_5&amp;diff=22864&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Notes==  &lt;pre&gt; Lecture 5 ---------  - project proposal, see class wiki  How will technical scope be graded?  - clean design  - doable implementation in time given  - testing...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Game_Engines_2021W_Lecture_5&amp;diff=22864&amp;oldid=prev"/>
		<updated>2021-01-26T17:25:05Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Notes==  &amp;lt;pre&amp;gt; Lecture 5 ---------  - project proposal, see class wiki  How will technical scope be graded?  - clean design  - doable implementation in time given  - testing...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 5&lt;br /&gt;
---------&lt;br /&gt;
 - project proposal, see class wiki&lt;br /&gt;
&lt;br /&gt;
How will technical scope be graded?&lt;br /&gt;
 - clean design&lt;br /&gt;
 - doable implementation in time given&lt;br /&gt;
 - testing your understanding of Godot&lt;br /&gt;
 - so, a mix of ambition and reason&lt;br /&gt;
&lt;br /&gt;
Game engines - memory management&lt;br /&gt;
&lt;br /&gt;
 - does Godot use malloc/standard new?  NO&lt;br /&gt;
 - why not?&lt;br /&gt;
 - memory allocation is inherently expensive&lt;br /&gt;
 - how memory is managed has significant performance implications&lt;br /&gt;
   - so, makes sense to make some effort to do it &amp;quot;right&amp;quot; for any&lt;br /&gt;
     performance-oriented application&lt;br /&gt;
&lt;br /&gt;
the memory hierarchy&lt;br /&gt;
 - systems have a mix of small, fast, low latency memory and slow,&lt;br /&gt;
   high latency memory&lt;br /&gt;
&lt;br /&gt;
registers&lt;br /&gt;
TLB &amp;lt;- virtual memory&lt;br /&gt;
on-CPU cache (L1, L2)&lt;br /&gt;
external CPU cache (L3)&lt;br /&gt;
main memory&lt;br /&gt;
SSD&lt;br /&gt;
(Spinning) Hard Drives&lt;br /&gt;
Tape&lt;br /&gt;
&lt;br /&gt;
Every memory access starts with a virtual address but must end with a physical address&lt;br /&gt;
 - TLB is a cache of virtual-&amp;gt;physical mappings at the page level&lt;br /&gt;
   (every 4K of memory)&lt;br /&gt;
 - OS&amp;#039;s manage page tables which define the full virtual-&amp;gt;physical mapping,&lt;br /&gt;
   most modern chips have hardware walk the page tables to get TLB entries&lt;br /&gt;
&lt;br /&gt;
Part of why memory management is expensive is it ultimately requires&lt;br /&gt;
manipulating TLBs and page tables&lt;br /&gt;
 - so first rule of memory management in userspace is to ask the kernel&lt;br /&gt;
   to do it as infrequently as possible&lt;br /&gt;
 - reduce, reuse, recycle!&lt;br /&gt;
&lt;br /&gt;
Classic malloc isn&amp;#039;t shy about going to the OS for memory&lt;br /&gt;
 - yes, allocates in chunks&lt;br /&gt;
 - but, not so good at recycling&lt;br /&gt;
   - because of memory fragmentation&lt;br /&gt;
&lt;br /&gt;
Memory fragmentation means memory is used less efficiently&lt;br /&gt;
 - you get &amp;quot;holes&amp;quot; in memory that can&amp;#039;t be properly used&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
 - Let&amp;#039;s say you do a bunch of 1K allocations, that are randomly allocated then freed&lt;br /&gt;
 - after doing this for a while, you&amp;#039;ll have memory with randomly placed 1K holes, the allocations that you later de-allocated&lt;br /&gt;
 - then, you need 4K, or 8K, or...1MB&lt;br /&gt;
 - you can have that amount available, but in scattered 1K chunks&lt;br /&gt;
   - so, you have to go ask the OS for more memory :-(&lt;br /&gt;
   - or, you move things around to compact memory (this is basically garbage&lt;br /&gt;
     collection)&lt;br /&gt;
&lt;br /&gt;
 - the best strategies to avoid memory fragmentation make assumptions about&lt;br /&gt;
   patterns of allocation&lt;br /&gt;
    - thus, if you know how your application allocates memory, then&lt;br /&gt;
      you can probably develop a way to allocate memory that minimizes&lt;br /&gt;
      fragmentation&lt;br /&gt;
&lt;br /&gt;
Cache-friendly allocation&lt;br /&gt;
 - more to do with how you organize data structures wrt access patterns&lt;br /&gt;
 - should organize them so your &amp;quot;working set&amp;quot; at any time fits into the caches&lt;br /&gt;
&lt;br /&gt;
To get best performance, you want small data structures&lt;br /&gt;
 - so data structures can all be packed into cache&lt;br /&gt;
but small data structures means more allocations/deallocations&lt;br /&gt;
 - which hurt performance&lt;br /&gt;
&lt;br /&gt;
Core data type in Godot is Variant&lt;br /&gt;
 - can be used to represent almost anything&lt;br /&gt;
 - note, it allows for standard type checking to be completely&lt;br /&gt;
   bypassed (but Godot has its own mechanisms)&lt;br /&gt;
&lt;br /&gt;
By having a small data structure that is uniform in size but can represent&lt;br /&gt;
all kinds of data, it makes the memory allocation problem easier&lt;br /&gt;
 - just managing uniform-sized variant&amp;#039;s!&lt;br /&gt;
 - different kinds of data structures will get their own pools in general&lt;br /&gt;
&lt;br /&gt;
Note, not the most efficient in terms of space&lt;br /&gt;
 - some Variant types are smaller than 20 bytes&lt;br /&gt;
 - but still can improve performance&lt;br /&gt;
&lt;br /&gt;
Always trade-offs between time and space&lt;br /&gt;
&lt;br /&gt;
Variant is interesting for reasons beyond allocator efficiency&lt;br /&gt;
 - why implement your own type system?!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also see [https://docs.godotengine.org/en/stable/classes/class_variant.html Godot&amp;#039;s documentation on Variant].&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>