Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Where should pointers used in arenadata be initialized?

 
Post new topic   Reply to topic Printable version
 View previous topic  Mac Post :: Post Most stable distro for ASSS?  View next topic  
Author Message
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Jun 17, 2004 3:16 pm    Post subject: Where should pointers used in arenadata be initialized? Reply to topic Reply with quote

I'm looking at balls.c and how it handles per arena data allocation:

abdkey = aman->AllocateArenaData(sizeof(ArenaBallData));

so it gets a key for the data... now I'd assume any pointers in the data (like BallData *balls) would now contain a random value until i amalloc or malloc something for it. So my question is, where does this value get initialized?

The obvious answer is when the arena is created, so I looked in the AABall function:

void AABall(Arena *arena, int action)
{
/* create the mutex if necessary */
if (action == AA_CREATE)
{
pthread_mutexattr_t attr;

pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init((pthread_mutex_t*)P_ARENA_DATA(arena, mtxkey), &attr);
pthread_mutexattr_destroy(&attr);
}

LOCK_STATUS(arena);
if (action == AA_CREATE || action == AA_DESTROY)
{
ArenaBallData *abd = P_ARENA_DATA(arena, abdkey);

/* clean up old ball data */
if (abd->balls)
{
afree(abd->balls);
abd->balls = NULL;
}
abd->ballcount = 0;
}
if (action == AA_CREATE)
{
/* only if we're creating, load the data */
load_ball_settings(arena, 1);
}
....

it looks like the first thing it does if action == AA_CREATE is create some thread stuff... then it does if (action == AA_CREATE || action == AA_DESTROY)
and if (abd->balls)

then it'll free the memory pointed to by abd->balls. But if abd->balls is a random value(just been allocated) wouldn't it be trying to free a random memory location? It doesn't. I put a check in and when the arena is created abd->balls is zero so it skips that if statement. But where does abd become zero??? when you do allocatearenadata does it initialize all the data to zero?

Also: when should I do LOCK_STATUS(arena); and UNLOCK_STATUS(arena); ??? is that whenever I get or modify arena data? what about when I get player data? LOCK_PLAYER?

Thanks!!!
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Fri Jun 18, 2004 2:26 pm    Post subject: Reply to topic Reply with quote

The per arena/player data is always zero'd for you. (If you look in util.c amalloc() sets the mem to 0).

The LOCK_STATUS() is a macro specific only to the source file it is defined in. It is most likely used so two callbacks don't try and write to the same data at the same time (or maybe one callback is reading data).
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 61 page(s) served in previous 5 minutes.

phpBB Created this page in 0.424685 seconds : 26 queries executed (95.0%): GZIP compression disabled