Welcome, Guest. Please login or register.

What openbor you prefer: Double dragon,battletoads or final fight !? by lirexpatrio
[December 07, 2012, 07:15:27 pm]


what are your favorite games OpenBOR?! by lirexpatrio
[December 07, 2012, 07:09:46 pm]


Post Some Awesome Videos by maxman
[December 07, 2012, 05:51:39 pm]


Can @cmd playmusic "aaaa" 1 also increse music sound ? by BeasTie
[December 07, 2012, 05:24:38 pm]


Streets of Rage: Silent Storm by mtrain
[December 07, 2012, 03:45:05 pm]


Site will be down for maintenance on 12/8/2012 thru 12/10/2012 by Damon Caskey
[December 07, 2012, 07:42:42 am]


Cancelled SOR 3d Remake by riccochet
[December 07, 2012, 03:58:33 am]


Dungeon Fighter: B.O.R. by msmalik681
[December 07, 2012, 03:24:27 am]


[TUTORIAL] How to create 4 Games of OpenBOR in 1 CD (650 MB) by magggas
[December 06, 2012, 09:46:25 pm]


custknife by Bloodbane
[December 06, 2012, 09:34:09 pm]


blockfx help by B.Kardi
[December 06, 2012, 04:09:14 pm]


street of age 4 hd by corradlo
[December 06, 2012, 01:41:36 pm]


ClaFan - Classic Fantasy ver 1.17 by soniczxblade
[December 06, 2012, 05:01:20 am]


Bug Archive by Bloodbane
[December 06, 2012, 02:00:44 am]


"Bio-Doom" and "Gears of Doom" by BulletBob
[December 05, 2012, 10:07:21 pm]


Contra Locked 'N' Loaded v2 by Bloodbane
[December 05, 2012, 09:39:43 pm]


Downloadable OpenBoR Manual by BeasTie
[December 05, 2012, 08:31:24 pm]


Having trouble testing changes by B.Kardi
[December 05, 2012, 03:05:53 pm]


DragonBall Absalon by msmalik681
[December 05, 2012, 02:52:13 pm]


[Hi-Res] Swamp by Vibrant
[December 05, 2012, 10:47:14 am]


  • Dot Guests: 149
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.



Author Topic: About tracerealloc()  (Read 2542 times)

0 Members and 1 Guest are viewing this topic.

Offline Damon Caskey

  • Hero Member
  • *****
  • Posts: 5335
    • The Gorge
Re: About tracerealloc()
« Reply #15 on: February 28, 2011, 10:10:08 am »
pls stop discussing about that bullshit, or i have to invite the trolls from the ##C channel or reddit to teach you

And if you do, I'll put you and them in the same place. This kind of talk doesn't fly on Lavalit.

DC
OpenBOR Wiki.

Coming Soon:
Spoiler
Fatal Fury Chronicals


Offline SX

  • Administrator
  • Hero Member
  • *****
  • Posts: 2700
    • LavaLit
Re: About tracerealloc()
« Reply #16 on: February 28, 2011, 10:12:38 am »
Back to the subject at hand....


If its a fragmentation issue.  It might be worth putting in the time to try and get newlib compiled for windows.

A user from the ps2dev.org forum posted the following:

hrimfaxi:  NewLib-1.17
Quote
Hi, folks. Recently I found out if we update newlib-psp malloc version to the latest malloc-2.8.4, the memory fragment after a mass of allocating-and-freeing memory operations will significantly reduce.


I can verify that his statement holds true.... here is my own quote from that forum:
Quote
The Good News:
I went from 6246484 Bytes of fragmented memory to 4759612 Bytes. That's about 23.8% Savings!

The Bad News:
I still have quite a bit of fragmented memory...

Here is the link to the conversation: Click Me!


Bottom line here is that OpenBOR does cause memory to become fragmented.  You will definitely see this issue on embedded hardware such as the PSP, but If your running a Windows machine that is light on Ram....  The same issues are bound to happen.

Linux users by default have the latest and greatest version of newlib, and is probably why fragmentation does not hurt them as much as Windows with the same hardware specs.
« Last Edit: February 28, 2011, 10:20:36 am by SX »

Offline Damon Caskey

  • Hero Member
  • *****
  • Posts: 5335
    • The Gorge
Re: About tracerealloc()
« Reply #17 on: February 28, 2011, 10:19:52 am »
"significantly reduce"...

That doesn't sound like a great solution. There is a big difference between reduce and eliminate. If we still have fragmentation, even "significantly reduced", it's going to come back and bite us.

DC
OpenBOR Wiki.

Coming Soon:
Spoiler
Fatal Fury Chronicals


Offline SX

  • Administrator
  • Hero Member
  • *****
  • Posts: 2700
    • LavaLit
Re: About tracerealloc()
« Reply #18 on: February 28, 2011, 10:28:10 am »
"significantly reduce"...

That doesn't sound like a great solution. There is a big difference between reduce and eliminate. If we still have fragmentation, even "significantly reduced", it's going to come back and bite us.

DC


There is no great solution.

On one hand we use arrays, and have the space pre-allocated for the strings we use.  But then it just blindly increases the amount of total memory OpenBOR uses.  (Old days of OpenBOR)

On the other hand we allocate strings as needed.  Less memory is used, but fragmentation now occurs. (OpenBOR Today)

One user on that forum made an interesting statement.  I should use memory pools for specific areas.  Which is starting to make more sense.  For strings where we allocate 5, 10, 32 bytes or so, we should use a small pool dedicated for that very behavior.  

This will guarantee the heap does not get fragmented.   Same can apply to other areas, like sprites, etc... each get their own pool.


Lastly,
It might be worth spending the time to review all instances where tracemalloc is called.  I'm betting in some areas we can rely on the stack instead of the heap.  This will lower fragmentation as well, utilizing the stack whenever possible.
« Last Edit: February 28, 2011, 10:33:56 am by SX »

Offline Damon Caskey

  • Hero Member
  • *****
  • Posts: 5335
    • The Gorge
Re: About tracerealloc()
« Reply #19 on: February 28, 2011, 10:33:53 am »
Mind meeting in chat a sec?

DC
OpenBOR Wiki.

Coming Soon:
Spoiler
Fatal Fury Chronicals


Offline SX

  • Administrator
  • Hero Member
  • *****
  • Posts: 2700
    • LavaLit
Re: About tracerealloc()
« Reply #20 on: February 28, 2011, 10:34:24 am »
Sounds good.

Offline Plombo

  • Hero Member
  • *****
  • Posts: 1724
  • Your source for useful modding tools!
Re: About tracerealloc()
« Reply #21 on: February 28, 2011, 05:17:24 pm »

Okay, my current theory is that Windows + realloc() == fail.  Do you know if Windows has any issues with realloc() usage?
Um.................right. :-X
come on, if you take this vague feeling you had at the time serious, there's something wrong

Great, you decided to dig out some old posts I made in a different thread.

The first one is an incomplete theory I had three months ago.  I haven't actually believed that for 3 months.  It was a tentative guess until further evidence turned up, which it did.

The second post had absolutely nothing to do with realloc().  It was talking about something completely different (my personal modding project), and I have no idea why you quoted it.


Quote
and YES, even Microsoft uses realloc, because it simplifies memory management a lot, and leads to compacter and cleaner code

No, they use HeapRealloc, which is basically the same thing.  That's what I said before.



But whatever, I'm tired of talking about this crap, and I could be wrong.  If you're really that bothered by not being able to reallocate buffers in theoretically possible recursive functions without keeping track of their lengths (??? ??? ???) then let's just leave the stupid function like it is.

In fact, it's not like the following (or something with similar logic) is rocket science, or even close:
Code: [Select]
void* recursive_something(void* buf, size_t curlen)
{
    static size_t buflen;
    void* buf2;
    buflen = curlen;
    // [...] (change buflen at some point to new desired buffer size)
    buf2 = tracerealloc(buf, buflen);
    if(buf2 == NULL) { tracefree(buf); return NULL; }
    // [...]
    if(whatever_condition)
    buf2 = recursive(buf2, buflen);
    // [...]
    return buf2;
}

But if this theoretical function really is that painful, then like I said, have it your way.  I'm going to leave the function alone and not argue about it any more unless prompted.



If its a fragmentation issue.  It might be worth putting in the time to try and get newlib compiled for windows.

Using a non-default C library would not solve the problem...

Linux users by default have the latest and greatest version of newlib, and is probably why fragmentation does not hurt them as much as Windows with the same hardware specs.

Linux users don't have newlib at all.  We use glibc.  Newlib is primarily for embedded systems.

Also, on platforms that use, the important parts of memory management are handled by the kernel, not by the userspace C library.



"significantly reduce"...

That doesn't sound like a great solution. There is a big difference between reduce and eliminate. If we still have fragmentation, even "significantly reduced", it's going to come back and bite us.

It's already been biting us for years.  It's actually gotten better since the beginning of 2010, at the very least.  I don't see how it's going to "come back and bite us" any more than it already has unless we introduce even more fragmentation.

Offline utunnels

  • Developer
  • Hero Member
  • *****
  • Posts: 2713
Re: About tracerealloc()
« Reply #22 on: August 27, 2011, 08:22:07 pm »
Bump*

It seems I missed something big.  :laughing:
I want to know, how do we check memory leak in this new layout?

Offline Plombo

  • Hero Member
  • *****
  • Posts: 1724
  • Your source for useful modding tools!
Re: About tracerealloc()
« Reply #23 on: September 25, 2011, 04:46:24 pm »
Bump*

It seems I missed something big.  :laughing:
I want to know, how do we check memory leak in this new layout?

By default, nothing.  I think there's a tracemalloc replacement that you can enable at build time in debug mode.  I still wish tracemalloc hadn't been removed.

 



 0%




SimplePortal 2.3.3 © 2008-2010, SimplePortal