Memory Usage

Blitz3D Forums/Blitz3D Beginners Area/Memory Usage

Gauge(Posted 2005) [#1]
When I ran my mud project I started off with a memory usage of 1,200k according to task manager. When I connected with 1,000 players it went up to 3,296k. But when I disconnected all of them it stayed at 3,296. I'm running several subtypes withint p.player and was wondering if I have the type object in type player, should i delete the type object first, thent he player, or?

When i first start off the program i dim p.player(1000)
when i create a new player i do p(ucount)=new player
and when i delete the player, say player 10 is deleting I run a for/next loop so like:

for x=10 to ucount step 1
p(x)=p(x+1)
;and then delete the last user
delete p(ucount):ucount=ucount-1

Should I do this a faster way?


Stevie G(Posted 2005) [#2]
If you have types within types like so ..

Type Player
field w.weapontype
field otherstuff
end type

Then deleting a player type will not delete the weapontype so it will still linger in memory. You need to first delete the weapon type then the player type.

Note that there was an issue with how blitz handled the deleting of types / cleaning up memory prior to version 1.87 I think. I remember reading that Sean Swift tested this a while back.


big10p(Posted 2005) [#3]
The reason your memory useage doesn't go down after deleting players:

The memory used for type instances isn't properly freed (returned to the heap) until the program ends. Any instances you delete are only flagged internally as available for re-use when creating a new instance.


Gauge(Posted 2005) [#4]
Ahh I see, the problem with the memory not being freed is, well it seems to go up 0004k everytime I create a new user, which wouldn't be good for a multiplayer, eventually it'll eat up all the memory.

You said it flags the memory internally for later use, I tried and ran 300 connections, ate up some memory, then I deleted all of them. Ran 300 more connections, and it still ate more memory. So its not reusing that memory.

I'm going to try deleteing each subtype of the player, and if that doesn't do it, deleting each field also. Going to run a few tests and see if I can get the problem taken care of, any other suggestions??


Gauge(Posted 2005) [#5]
Heres what i'm doing when a new stream connects, and this is it:

Function checknew()
stream=AcceptTCPStream(server)
If stream Then
Print "*CONNECTION RECIEVED!*"
ucount#=ucount#+1
x=ucount#
pl (x)=New Player
pl (x)\name$="Logon........................................................................................."
pl (x)\stream=stream
pl (x)\status=Menu
pl (x)\prace$="None"
pl (x)\pclass$="None"
pl(x)\sex$="None"
pl (x)\comm1$=""
pl (x)\comm2$=""
pl (x)\comm3$=""
pl (x)\comm4$=""
pl (x)\msg$=""
pl (x)\comm=1
pl (x)\PlayerId=x
displaymenu pl(x)
end function

and when i delete the players this is what i'm using:

function Logoff(p.player)
If p\status=playing deletealsohere p
If Not Eof(p\stream)
Deletealsohere p
Print p\name$+" has logged off!"
WriteLine p\stream, "GOODBYE!...come back soon!"
CloseTCPStream(p\stream)
EndIf
jhk=p\playerID
;Print "player id deleteing: "+jhk
For x=1 To ucount# Step 1
If pl(x)\playerid>jhk Then
k=x-1
stream=pl(x)\stream
pl (k)\stream=stream
;Print "player_id"+pl(x)\playerID+" larger Then A!="+a
pl(k)\playerid=pl(x)\PlayerId-1
pl(k)\status=pl(x)\status
pl(k)\level=pl(x)\level
pl(k)\name$=pl(x)\name$
pl(k)\password$=pl(x)\password$
pl(k)\password$=pl(x)\Curr_Area
pl(k)\curr_room=pl(x)\curr_room
pl(k)\title$=pl(x)\title$
pl(k)\pclass$=pl(x)\pclass$
pl(k)\prace$=pl(x)\prace$
pl(k)\pracenumber=pl(x)\pracenumber ;?
pl(k)\pclassnumber=pl(x)\pclassnumber;?
pl(k)\sex$=pl(x)\sex$
pl(k)\comm=pl(x)\comm
pl(k)\experience#=pl(x)\experience#
pl(k)\baseexp#=pl(x)\baseexp#
pl(k)\exptnl#=pl(x)\exptnl#
EndIf
Next
Print "Deleting player# "+ucount#
Delete pl(ucount#)
If ucount#=<1 Then
For px.player=Each player
Print px\playerid
Next
EndIf
ucount#=ucount#-1
end function