Visit Our UNIX and Linux User Community


Two player game, forking & sockets


 
Thread Tools Search this Thread
Top Forums Programming Two player game, forking & sockets
# 8  
Old 06-07-2011
Quote:
Originally Posted by Shang
I read on stackoverflow.com that it is more portable.
I'm pretty sure mmap is more fundamental. shm() will also work, but I prefer mmap, it's more flexible. I also like the idea of being able to map in massive things from disk without wasting untold amounts of memory; whereas the memory the system will allow you to shm() may be fairly limited, and eats swap.
Quote:
Oh, I haven't noticed that fact. Good to know.Ok, I will remember that.Do you mean that below code is wrong?
Not wrong, no. It illustrates an important feature of shm, getting at anonymous memory from the outside. Just knowing the name can get you the memory, where mmap() would need to map an actual file to get at already-in-use segments a process didn't inherit. Remember though, a UNIX system is supposed to back all memory with disk one way or another. If you don't let it be on disk, it may just end up in swap.
Quote:
I think that is my problem. What does it mean big enough?
Well, how large are your structures? Think in terms of available memory, not in clients. Many programs have that kind of configurable maximum; use this much memory but no more. mmap makes this simple because you can map in the max amount of memory without actually using it. The OS will just give you more when you use it, up to the max you requested.

Many programs have a configurable limit for that sort of upper max. I recall a chess program that took a configurable amount of space for its memory buffer. It couldn't run as a limited user until fiddled with settings in /proc though because shm only gives limited users 16 megs or so by default in Linux. With file-backed mmap, hundreds of megs is the practical limit for one segment in 32-bit; and on 64-bit, the sky is the limit.
Quote:
Server doesn't know how much clients would have. The main point is how to organize this shared memory to grow as new games are started. Good idea, thanks Smilie
You only want it to grow to a point. You don't want it to eat beyond all available memory and grind your machine into swapdeath. Pick a fraction of total RAM maybe.
Quote:
I am not sure if I understand well. Could you propose any sketch?
Code:
// one way
struct mystruct
{
        int a;
        char b;
        float c;
};

// No arbitrary sizes
struct mystruct *myarray=malloc(sizeof(mystruct)*5000);
// or
struct mystruct *myarray=mmap(...);
// or shmat, etc etc.

struct otherstruct
{
        int a[5000];
        char b[5000];
        float c[5000];
};

// Size stuck at 5000
struct otherstruct otherarray;

It could be that I misunderstood the intent of the structure you posted though. I have no idea how you plan to organize this memory yet.

Last edited by Corona688; 06-07-2011 at 08:53 PM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #733
Difficulty: Medium
AmigaBASIC is a complied BASIC programming language implementation for the Amiga, designed and written by Microsoft.
True or False?

8 More Discussions You Might Find Interesting

1. Linux

Unable to install VLC media player or any other player in SL 6.3 distro

Hi, I am unable to install VLC or any other media players in my SL 6.3 distro. I am using yum utility to install the packages, but i am getting the below error messages, --> Processing Dependency: libpng15.so.15()(64bit) for package: vlc-core-2.0.3-1.fc18.x86_64 --> Processing... (1 Reply)
Discussion started by: vel4ever
1 Replies

2. Programming

need help in forking

I have an input file with contents like: 5785690|68690|898809 7960789|89709|789789 7669900|87865|659708 7869098|65769|347658 so on.. I need to pass this file to 10 parallely running processes (forking)so that each line is processed by a process and no line is processed twice and write the... (1 Reply)
Discussion started by: rkrish
1 Replies

3. Programming

forking within a thread

Is it safe to call fork+exec in a multithreaded application. Because In my multithreaded application, I need to execute another program in each thread. I am using solaris 10. Any suggestions pls. (2 Replies)
Discussion started by: axes
2 Replies

4. HP-UX

Mozilla & Macromedia Flash Player Plugin Problem

Hello All, I am using Mozilla 1.7.8 on hp-ux 11.00, and install flash player 6 for it. it is giving following errors and get crashed. when i want to open a site need flash plugin. Gtk-WARNING **: invalid cast from `GtkSuperWin' to `GtkWidget' Gtk-WARNING **: invalid cast from `GtkSuperWin'... (1 Reply)
Discussion started by: Awadhesh
1 Replies

5. UNIX for Advanced & Expert Users

Forking

When I compile this C programme I get different outputs each time I run it Please explain to me whats happening in the code if you can give me a detailed explanation with the schedular functionality it will help a lot. Because I am stuck with this. #include <stdio.h> main(){... (3 Replies)
Discussion started by: manjuWicky
3 Replies

6. Programming

Forking in a loop

When I compile this C programme I get different outputs each time I run it Please explain to me whats happening in the code if you can give me a detailed explanation. Because I am stuck with this. #include <stdio.h> main(){ int i = 0; printf("I am the... (1 Reply)
Discussion started by: manjuWicky
1 Replies

7. Linux

Having player problem && need your help.

My System is FC3, The following Players don't run well: 1).Helix Player couldn't play MP3 and *.wma files, 2).Totem is the same, 3)XMMS couldn't play .wma files. I am a newer of Linux,but I like Linux,just as you. Could you help me? Thank you! (1 Reply)
Discussion started by: letcorpmuv
1 Replies

8. UNIX for Dummies Questions & Answers

Association b/w sockets & processes

Hi, Is there any way i can know the association between sockets and the processes which created them. :confused: (5 Replies)
Discussion started by: soorajmu
5 Replies

Featured Tech Videos