My RB application's free RAM is terribly fragmented :-( 
Author Message
 My RB application's free RAM is terribly fragmented :-(

I have a RB application that works like a word processor: it can open
existing documents or create new documents, each of them in a new window.
Each time the application creates a new window, it takes about 70 Kb of
RAM.
The problem is when I close all these windows, the application's free
RAM is totally fragmented. So even if I have a large amount of total
free RAM I just can't open a new window :-(

I use this code to see how is the RAM:
------------------
  dim freeRam,largestBlock as integer
  '
  Declare Function MaxBlock Lib "InterfaceLib" () as Integer
  freeRam = FreeMem()\1024 // plug-in
  largestBlock = MaxBlock()\1024
  msgBox "Total free RAM: " + str(freeRam) + ret + "Largest block: " +
str(largestBlock) + ret + "Fragmented RAM: " + str(freeRam-largestBlock)
------------------

Can someone tell me how could I compact the fragmented RAM?

Thanks for your help!



Fri, 26 Mar 2004 15:20:32 GMT  
 My RB application's free RAM is terribly fragmented :-(

Quote:

> The problem is when I close all these windows, the application's free
> RAM is totally fragmented. So even if I have a large amount of total
> free RAM I just can't open a new window :-(
[...]
> Can someone tell me how could I compact the fragmented RAM?

I can't answer your question (sorry) but this strikes me as really odd
because I was under the impression that the Memory Manager compacted
the application's memory heap for you automatically. The only thing I
could imagine would be causing your problem is if somehow the memory
being allocated to your windows was being done so with nonrelocatable
blocks, in which case, the Memory Manager wouldn't be able to move them
when memory is being compacted.


Fri, 26 Mar 2004 17:52:52 GMT  
 My RB application's free RAM is terribly fragmented :-(

Quote:



> > The problem is when I close all these windows, the application's free
> > RAM is totally fragmented. So even if I have a large amount of total
> > free RAM I just can't open a new window :-(
> [...]
> > Can someone tell me how could I compact the fragmented RAM?

> I can't answer your question (sorry) but this strikes me as really odd
> because I was under the impression that the Memory Manager compacted
> the application's memory heap for you automatically. The only thing I
> could imagine would be causing your problem is if somehow the memory
> being allocated to your windows was being done so with nonrelocatable
> blocks, in which case, the Memory Manager wouldn't be able to move them
> when memory is being compacted.

Maybe you are right, but I really don't know how and why my damned
windows use nonrelocatable memory blocks! :-(
HELP !!!


Sat, 27 Mar 2004 01:12:35 GMT  
 My RB application's free RAM is terribly fragmented :-(

Quote:

> I use this code to see how is the RAM:
> ------------------
>   dim freeRam,largestBlock as integer
>   '
>   Declare Function MaxBlock Lib "InterfaceLib" () as Integer
>   freeRam = FreeMem()\1024 // plug-in
>   largestBlock = MaxBlock()\1024
>   msgBox "Total free RAM: " + str(freeRam) + ret + "Largest block: " +
> str(largestBlock) + ret + "Fragmented RAM: " + str(freeRam-largestBlock)
> ------------------

I wouldn't take this measurement too seriously.  RB has its own
internal memory management, and neither FreeMem nor MaxBlock knows
anything about that.

Cheers,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Sat, 27 Mar 2004 01:39:42 GMT  
 My RB application's free RAM is terribly fragmented :-(

Quote:

> I have a RB application that works like a word processor: it can open
> existing documents or create new documents, each of them in a new
> window. Each time the application creates a new window, it takes about
> 70 Kb of RAM. The problem is when I close all these windows, the
> application's free RAM is totally fragmented. So even if I have a
> large amount of total free RAM I just can't open a new window :-(

Your RAM is just fine, the problem is that RB has it's own RAM
management scheme, that doesn't release the RAM back to the MacOS.

So you have the RAM there, but... FreeMem can't see it.

We *really* need some way to access the amount of free RAM in RB. RS
has not provided this for us, and it is really a simple thing for them
to add.

As for a work around, I don't know if there are any good ones. I would
suggest not using FreeMem, and instead just making the new window. Try
trapping for exceptions when you do this, and if you get one, then
produce the out of RAM error.

That is one possible route....

Another is to make a newmemoryblock of the size of RAM that you need.
If it appears, you have that RAM free, if not, you don't. Then nil the
MB. Of course, that is a real "trial and error" solution.

To be honest, i don't have any good solutions.

I suggest REALbugging this, as a request.

--
Email Cleaner does convenient re-wrapping on badly wrapped emails and
newsgroup-posts. Badly wrapped lines is a problem every Internet User
comes across, Email Cleaner solves it! It also has many other features.

Email Cleaner works from inside all of your Mac programs, from one
button click.

<www.elfdata.com/emailcleaner/>



Sat, 27 Mar 2004 06:55:18 GMT  
 My RB application's free RAM is terribly fragmented :-(

Quote:


> > I have a RB application that works like a word processor: it can open
> > existing documents or create new documents, each of them in a new
> > window. Each time the application creates a new window, it takes about
> > 70 Kb of RAM. The problem is when I close all these windows, the
> > application's free RAM is totally fragmented. So even if I have a
> > large amount of total free RAM I just can't open a new window :-(

> Your RAM is just fine, the problem is that RB has it's own RAM
> management scheme, that doesn't release the RAM back to the MacOS.

Aren't there some programmer's utilities that map free memory, heap
space, etc?


Sat, 27 Mar 2004 13:50:33 GMT  
 My RB application's free RAM is terribly fragmented :-(

[..]

Quote:
> Another is to make a newmemoryblock of the size of RAM that you need.
> If it appears, you have that RAM free, if not, you don't. Then nil the
> MB. Of course, that is a real "trial and error" solution.

[..]

Here's some pseudocode:

dim block, memArray(-1) as MemoryBlock
dim blockSize, totalSize as integer
// arbitrary block size. change for however
// much RAM you want to test for.
blockSize = 4096
totalSize = 0
while blockSize > 1
  block = newMemoryBlock(blockSize)
  if block <> nil then
    memArray.append block
    totalSize = totalSize + blockSize
  end if
  blockSize = blockSize / 2
wend
return totalSize

Quote:
> I suggest REALbugging this, as a request.

Certainly App.FreeMemory would be better than making an array of
MemoryBlocks. :-)

--
"In a world full of lies/That tug at the truth
 I'm taking no sides/Now I recognize you..." --DS



Sat, 27 Mar 2004 16:20:27 GMT  
 My RB application's free RAM is terribly fragmented :-(

Quote:

> We *really* need some way to access the amount of free RAM in RB. RS
> has not provided this for us, and it is really a simple thing for them
> to add.

No, it's not.  It if were we'd have added it.

Cheers,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Sat, 27 Mar 2004 22:39:48 GMT  
 My RB application's free RAM is terribly fragmented :-(

Quote:

> I have a RB application that works like a word processor: it can open
> existing documents or create new documents, each of them in a new window.
> Each time the application creates a new window, it takes about 70 Kb of
> RAM.
> The problem is when I close all these windows, the application's free
> RAM is totally fragmented. So even if I have a large amount of total
> free RAM I just can't open a new window :-(
> Can someone tell me how could I compact the fragmented RAM?

Is it possible to force the RB application to compact the fragmented
free RAM using

Declare Sub HPurge Lib "InterfaceLib" (h as Integer)
Inline68K("205FA049")

???
If yes, how can I handle this "InterfaceLib" command and what "h as
integer" must be passed as parameter ?

Thanks!



Sat, 27 Mar 2004 22:40:56 GMT  
 My RB application's free RAM is terribly fragmented :-(

Quote:

>> Another is to make a newmemoryblock of the size of RAM that you need.
>> If it appears, you have that RAM free, if not, you don't. Then nil
>> the MB. Of course, that is a real "trial and error" solution. [..]
> Here's some pseudocode:

Hi Paul, I have a far better technique than this!

It is the wonderful "by half" technique, similar to what is used in a
"Binary search".

Basically, you do, something like this:

  #pragma disablebackgroundtasks
  #pragma disableboundschecking
  dim currVal, lMax, lMin as integer
  dim mb as MemoryBlock

  while lmin - lmax > 10*1024
    CurrVal = ( lmin + lmax ) \ 2
    mb = NewMemoryBlock(CurrVal)
    if mb = nil then
      lmax = currVal - 1
    else
      lmin = currVal + 1
    end if
  wend

  return CurrVal

OK, this isn't tested, and it certainly needs some modification
to actually get it to work at all ;o), but you should get the
idea. Basically, it should "home" in, onto the value you have
free.

--
Email Cleaner does convenient re-wrapping on badly wrapped emails and
newsgroup-posts. Badly wrapped lines is a problem every Internet User
comes across, Email Cleaner solves it! It also has many other features.

Email Cleaner works from inside all of your Mac programs, from one
button click.

<www.elfdata.com/emailcleaner/>



Mon, 29 Mar 2004 07:04:56 GMT  
 My RB application's free RAM is terribly fragmented :-(

Quote:

> Aren't there some programmer's utilities that map free memory, heap
> space, etc?

There are, but they don't know what RB is doing with it's RAM
internally. Only RB knows about that.

--
Email Cleaner does convenient re-wrapping on badly wrapped emails and
newsgroup-posts. Badly wrapped lines is a problem every Internet User
comes across, Email Cleaner solves it! It also has many other features.

Email Cleaner works from inside all of your Mac programs, from one
button click.

<www.elfdata.com/emailcleaner/>



Mon, 29 Mar 2004 07:05:35 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Adding 'Applescriptability' to a RB application

2. Instruction fragment with x'608'(0,0)

3. Getting an application's name from within RB

4. What's wrong with my rep movsb fragment

5. I am clinically stupid. (fastcgi.rb bug)

6. displaying free ram

7. How Come So Terribly Slow ????

8. Speedup games, programs and get more FREE RAM

9. Free Memory (ram)

10. Conversion of Altera Block RAM to Xilinx Block RAM

11. Read latency of block ram disappears when ram is clocked from bufgce

12. RAM and RAM model

 

 
Powered by phpBB® Forum Software