LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 08-31-2004, 03:11 AM   #1
jhon
Member
 
Registered: Aug 2004
Posts: 32

Rep: Reputation: 15
allocation


Hi.,

Q1) does anybody know if there's a problem using malloc/ new instead of calling the GlobalAlloc windows API function:

struct Sock{ ... }

(Sock*)GlobalAlloc(GPTR, sizeof(SOCKET_INFORMATION))?

Q2) what is the meaning of GPTR and what's its replacement in UNIX?
 
Old 08-31-2004, 03:38 AM   #2
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
The GlobalAlloc function allocates the specified number of bytes from the heap. Windows memory management does not provide a separate local heap and global heap.

GMEM_FIXED ---->>> Allocates fixed memory. The return value is a pointer.

GMEM_ZEROINIT ---->>> Initializes memory contents to zero.

GPTR ---->>> Combines GMEM_FIXED and GMEM_ZEROINIT.

So GPTR means " Allocates fixed memory and Initializes memory contents to zero".

And about using them in unix you can allocate the memory using malloc/new but you just keep in mind that you have to implement the GPTR or any other flag used yourself. In this case you just have to allocate the memory and initialize contents to zero.
 
Old 08-31-2004, 07:02 AM   #3
jhon
Member
 
Registered: Aug 2004
Posts: 32

Original Poster
Rep: Reputation: 15
>>And about using them in unix you can allocate the memory using malloc/new but you just keep in mind that you have to implement the GPTR or any other flag used yourself. In this case you just have to allocate the memory and initialize contents to zero. [/B][/QUOTE]

Q1) sorry for the ignorance but what is the meaning of initializing contents to 0. should I use any macro?

Q2) what is the meaning of allocating fix memory size (GMEM_FIXED)? isn't it built it part of malloc(size of(XXX))?

Q3) do you know the equivalent of closesocket(int) in UNIX? is close(int) just the same?

Q4) any equivalent to GlobalFree(HGLOBAL)?

thanks again. it's the last thing I need...

Last edited by jhon; 08-31-2004 at 07:08 AM.
 
Old 08-31-2004, 09:52 AM   #4
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
To allocate memory and set it to zero you can use calloc() instead of malloc().

calloc() allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. The memory is set to zero.

malloc() allocates size bytes and returns a pointer to the allocated memory. The memory is not cleared.

And about GlobalFree(HGLOBAL), here HGLOBAL is the handle returned by the GlobalAlloc() or GolbalReAlloc() function, so now you are allocating the memory using calloc() so you just use free() to free the memory. And don't care about FIXED memory its alright.

And "YES" colsesocket() in windows is equalent to colse() in linux.

Last edited by cppkid; 08-31-2004 at 09:53 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help - memory allocation in C zaichik Programming 3 09-04-2005 11:16 AM
CPU Allocation j0ntar Linux - Software 2 02-20-2005 07:33 PM
Port Allocation anirudh Programming 1 11-02-2004 03:04 PM
memory allocation docGonzo2000 Linux - General 1 05-16-2003 10:24 PM
memory allocation docGonzo2000 Linux - General 1 05-16-2003 10:22 PM


All times are GMT -5. The time now is 12:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration