• 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.

Archived

This topic is now archived and is closed to further replies.

Zoomby

how does a (the) heap work?

5 posts in this topic

hi! can someone explain how a (the c++) heap works? Or do you know a good site where it is explained? How does the heap itself allocate memory? Is it possilbe to write own malloc-functions without touching the standard malloc-functions? bye chris
0

Share this post


Link to post
Share on other sites
The C runtime provided by for instance Visual C++ implements malloc for you. Malloc will handle allocation of memory from the operating system.

For instance malloc in the Visual C++ runtime library (msvcr70.dll or msvcr70d.dll) will eventually call RtlAllocateHeap in kernel32.dll, which will switch to kernel mode to allocate memory from the memory manager in NT.

The debug and release versions of the Visual c++ runtime are a bit different (more debug help and less performance in the debug version). If you installed the CRT source during visual studio install (you should!) you can look in C:\Program Files\Microsoft Visual Studio .NET\Vc7\crt\src to find the malloc implementation (malloc.c, dbgheap.c).

Since it''s relatively costly to allocate memory from the operating system, a memory manager often keeps some allocated memory ''cached'', so that when you call malloc(size), malloc will first look in a (quite small) list of memory blocks to see if one is available for your call, and if so give you that block and remove it from the list. Otherwise a call to the OS is necessary. When you call free, either memory is put in that list of free blocks, or returned to the OS. There are tons of optimizations that could be done, but my description should at least give you a clue how it works.
0

Share this post


Link to post
Share on other sites
On *NIX platforms the memory managed by malloc is generally allocated from the operating system by the sbrk() system call.

http://gee.cs.oswego.edu/dl/html/malloc.html
describes a common, specific, *NIX malloc algorithm.

In general I wouldn''t recommend using sbrk() to implement your own malloc-like functions as that can mess with the standard library dynamic memory allocations. I believe on most *NIX platforms you could use mmap(), but it tends to be slow. If you want to implement custom memory management, it usually turns out easier (and more portable) if you implement it on top of existing malloc functionality.
0

Share this post


Link to post
Share on other sites
thanks,

but I use Windows. Is the "RtlAllocateHeap" function documented in MSDN? I could''nt find it.

bye
chris
0

Share this post


Link to post
Share on other sites
quote:
can someone explain how a (the c++) heap works?


Most C++ programmers never touch the heap. In most cases you would be better served by the free store.

quote:
Or do you know a good site where it is explained?


There should be a lot of good sites. Try google. Or get a book such as The C++ Programming Language by Bjarn Stroustrop.

quote:
How does the heap itself allocate memory?


By making a call to the operating system''s memory manager, which in turn works with the hardware to manage RAM in chunks called pages. More information on this can be found in your processor manufacturer''s architecture manuals and in semi-architecture-agnostic books like Modern Operating Systems by Andrew Tanenbaum.

quote:
Is it possilbe to write own malloc-functions without touching the standard malloc-functions?


Yes, if you make the system calls yourself. It is probably one of those things that if you do not understand how to do it, you have no idea when it ought to be used.
0

Share this post


Link to post
Share on other sites
quote:
Original post by Zoomby
Is the "RtlAllocateHeap" function documented in MSDN? I could''nt find it.
RtlAllocateHeap is a kernel32.dll internal function and should never be called directly. Instead you should use HeapAlloc or LocalAlloc.

You can read more about NT''s memory handling here: http://www.winntmag.com/Articles/Index.cfm?IssueID=56&ArticleID=3686
0

Share this post


Link to post
Share on other sites