• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
  • entries
    743
  • comments
    1924
  • views
    578332

Reference counted garbage collection

Sign in to follow this  
Followers 0
Aardvajk

363 views

Bit too tired to write this up in detail, but I've got an interesting system working in the VM now where, as per ApochPiQ's advice last post, I'm now using reference counted garbage collection. A buffer is also tagged to say whether it points to a list of allocated buffers and if so, when it is freed it decrements the references of its members recursively, freeing them if needed.

I've implemented arbitrary dimensional arrays in the compiler and got everything working at run-time using a Copy On Write system that utilises the reference counting built into the VM. For what it is worth:

[source]

char[][][] c={ { "hello","world" },{ "hi","there" } };
char[][][] d=c;

out c[0][1],"\n";
out c[1][1],"\n";
out d[0][1],"\n";
out d[1][1],"\n";

c[0][1]="paul";
d[1][1]="froob";

out c[0][1],"\n";
out c[1][1],"\n";
out d[0][1],"\n";
out d[1][1],"\n";
[/source]

Compiles to (deep breath):

[source]

setrxi 2
push
setrxi 4
push
muli
pop
alloc
setrxi 1
setbt
movar
push
movar
push
setrxi 2
push
setrxi 4
push
muli
pop
alloc
setrxi 1
setbt
movar
push
movar
push
setrxi string1
push
axstm 8
get
movra
pop
put
pop
addax 4
movar
push
setrxi string2
push
axstm 8
get
movra
pop
put
pop
axstm 4
get
movra
incref
axstm 8
get
movra
pop
put
pop
addax 4
movar
push
setrxi 2
push
setrxi 4
push
muli
pop
alloc
setrxi 1
setbt
movar
push
movar
push
setrxi string3
push
axstm 8
get
movra
pop
put
pop
addax 4
movar
push
setrxi string4
push
axstm 8
get
movra
pop
put
pop
axstm 4
get
movra
incref
axstm 8
get
movra
pop
put
pop
axstm 4
get
movra
incref
axstm 4
get
push
axstm 4
get
movra
incref
axstm 8
get
push
setrxi 0
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
pop
outs
setrxi string5
push
pop
outs
axstm 8
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
pop
outs
setrxi string5
push
pop
outs
axstm 4
get
push
setrxi 0
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
pop
outs
setrxi string5
push
pop
outs
axstm 4
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
pop
outs
setrxi string5
push
pop
outs
axstm 8
get
movra
detach
movar
axstm 8
put
setrxi string6
push
axstm 12
get
push
setrxi 0
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
push
get
movra
decref
pop
movra
pop
put
push
pop
gc
axstm 4
get
movra
detach
movar
axstm 4
put
setrxi string7
push
axstm 8
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
push
get
movra
decref
pop
movra
pop
put
push
pop
gc
axstm 8
get
push
setrxi 0
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
pop
outs
setrxi string5
push
pop
outs
axstm 8
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
pop
outs
setrxi string5
push
pop
outs
axstm 4
get
push
setrxi 0
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
pop
outs
setrxi string5
push
pop
outs
axstm 4
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
setrxi 1
push
axstm 4
get
push
axstm 12
get
movra
pop
chkbi 4
setrxi 4
push
muli
addi
pop
movra
get
push
pop
outs
setrxi string5
push
pop
outs
pop
movra
decref
pop
movra
decref
gc
exit

-1 1 0 string5: 10b
-1 5 0 string7: "froob"
-1 5 0 string1: "hello"
-1 2 0 string3: "hi"
-1 4 0 string6: "paul"
-1 5 0 string4: "there"
-1 5 0 string2: "world"
[/source]

And correctly outputs what you would expect if deep copies of the arrays were being made. In fact the two arrays point to the same memory until the c[0][1]="paul" line, at which point a clone is created which c points to. When d[1][1]="froob" is executed, the same happens but as d only now has one reference, the cloning is skipped.

My god this stuff is hard to get right and to debug when it goes wrong. Wish my project was proceeding at the pace that Deyja's VM/compiler project was, but then I've written lots of these before and really wanted to see if I could get this nonsense to work.

This is an example of the VM running in debug mode, just to give you an idea of what I am staring at while going mad trying to work out what is broken.

[source]
Om 1.0 Copyright(C)2011 Aardvajk Software
REGISTERS:
pc : 5
ir : setrxi (11)
st : 1402
rx.i: 2
rx.f: 2.8026e-045
ax : 2004270470
cx : -1
ALLOCATED BLOCKS:
FREE BLOCKS:
2426: 1024
MEMORY SIZE: 3450
REGISTERS:
pc : 6
ir : push (21)
st : 1406
rx.i: 2
rx.f: 2.8026e-045
ax : 2004270470
cx : -1
ALLOCATED BLOCKS:
FREE BLOCKS:
2426: 1024
MEMORY SIZE: 3450
REGISTERS:
pc : 11
ir : setrxi (11)
st : 1406
rx.i: 4
rx.f: 5.60519e-045
ax : 2004270470
cx : -1
ALLOCATED BLOCKS:
FREE BLOCKS:
2426: 1024
MEMORY SIZE: 3450
ALLOCATED BLOCKS:
STACK:
1402: 2 (2)
1403: 0
1404: 0
1405: 0
[/source]

Need to think about array resizing next really. Not much point having dynamic arrays in a language if they, er, aren't.

0
Sign in to follow this  
Followers 0


4 Comments


Part of the reason I'm moving so fast is that I'm writing the virtual machine in C#. My stack is a stack of Objects, my registers are Objects, and my 'classes' are an array of objects. I pay a performance penalty but I don't have to deal with figuring out the size of objects on the stack or do any sort of memory management.
0

Share this comment


Link to comment
Yeah, I think these are very different projects, although it's kind of fun that there are two VM/compiler projects running at a roughly similar development level in journal-land at the same time.

Mine is a complete curiosity. Being written purely for the masochistic joy of seeing if I can make this work.
0

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now