Psy-Q lib.c issues

General help for the PSY-Q SDK, such as setting the SDK up, compiling correctly, linking and debugging
Post Reply
jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: August 13th, 2013, 7:58 am

Psy-Q lib.c issues

Post by jman » October 20th, 2013, 1:14 am

I've found in the official SCEE Playstation Developer's guide (v2.9) a note about memory management functions:
Dynamic Memory Allocation and the Heap

(...cut...)
In C, memory allocation is achieved using the malloc and free functions. Unfortunately there have been several problems with these functions on PlayStation.
The standard malloc/free combination supplied as part of libc fragments memory due to a bug in the free function. This means that large chunks on the machine memory become inaccessible even though they are not holding any valid data.
There is a patch for this bug which is used by linking with a file called mmgm.obj (available from the SCEE WEB SITE). This supplies a new function for initialising the heap and replaces the buggy malloc and free with more reliable functions. In this scheme the heap base is unconventionally located at the address ramsize minus the stacksize and the heap “grows” toward the base of memory.
Whilst these functions are better than the originals, they are still comparatively untested. Also they are rather generic. You are strongly recommended to consider developing a memory allocation scheme that is tailored to your specific application, rather than relying on those supplied in the libraries.
An example showing how to implement a simple malloc/free scheme is presented in the Kernighan & Ritchie book The C Programming Language. This text notes that the optimal memory allocation scheme depends on the nature of the application.
Just out of curiosity, how much this impacts PSX programming? I guess for small applications this may be unnoticeable.
Does anyone have more info/experience about this?
Does this issue has ever been solved (to our knowledge) by Sony over time?

Thanks

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 140
Joined: December 19th, 2012, 8:08 pm
IRC: t0rxe
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Re: Psy-Q lib.c issues

Post by t0rxe » October 20th, 2013, 3:27 pm

Sony solved it by updating Malloc to Malloc3. So just use Malloc3. It's an updated version of Malloc :D
As for how Malloc works, I'll dig up my drawings of the memory management so you can see how Malloc uses the memory. It's extremely useful, and makes working with the 2MB of RAM a lot easier and faster :)
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: August 13th, 2013, 7:58 am

Re: Psy-Q lib.c issues

Post by jman » October 21st, 2013, 12:12 am

Thank you for providing the right keyword ("malloc3"), I've found the reference in the libref46.pdf document.
I'm also interested in this specific implementation of the malloc()/free(). Some low-level knowledge never harms, even if just doing simple things.

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 140
Joined: December 19th, 2012, 8:08 pm
IRC: t0rxe
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Re: Psy-Q lib.c issues

Post by t0rxe » November 9th, 2013, 1:54 am

Here is one without the malloc() routine implemented. I will make the malloc version tomorrow ;)
viewtopic.php?f=47&t=463
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest