Sponsored Content
Top Forums Programming mmap and malloc, whats the difference? Post 302461578 by jim mcnamara on Monday 11th of October 2010 05:25:42 PM
Old 10-11-2010
A lot. mmap reads a file from disk, loads it into memory, and presents a memory mapped file. The memory section can be readonly or writable. Writing will update the underlying file on disk, with some limitations.

malloc allocates heap memory and returns a pointer to the freshly available memory.
It does not point to any valid data. You have to zero it out, then put your own data in there, you do not malloc and then use that result for mmap.
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

mmap

Hello. I'm writing some random access i/o software on Solaris 8 using mmap64 to memory map large files (my test file is ~25 GB). The abbreviated code fragment is: fd = open(cbuf,O_RDONLY|O_LARGEFILE); struct stat statbuf; fstat(fd,&statbuf); off_t len =... (0 Replies)
Discussion started by: gusm
0 Replies

2. UNIX for Dummies Questions & Answers

Whats the difference between...

the various distros of free Linux and other *nix OSes? I'm curious. (1 Reply)
Discussion started by: hype.it
1 Replies

3. UNIX for Dummies Questions & Answers

Linux OR Unix Whats The Difference!

What is the difference bettween linux and unix? Sorry but I am really new to this! :confused: Also are they BOTH free :-D (1 Reply)
Discussion started by: jamesthemagicia
1 Replies

4. Shell Programming and Scripting

whats the difference between $* and $@

Hi, whats the difference between $* and $@ in command line arguments to a shell scripts (3 Replies)
Discussion started by: pbsrinivas
3 Replies

5. UNIX for Dummies Questions & Answers

whats the difference between zombie orpha and defunct processes

can some one please explain zombie orphan defunct and how they r related (3 Replies)
Discussion started by: pbsrinivas
3 Replies

6. UNIX for Dummies Questions & Answers

Whats the difference between $status and $?

Hi, In linux we have exit status variable ($?) and status which tells whether last command was successfull or not. Can someone please tell me what is difference between both. Both tells whether command was successful or not, Any particular difference between them? Thanks in Advance. Thanks... (3 Replies)
Discussion started by: sarbjit
3 Replies

7. Programming

mmap()

how to use mmap() to map a file to memory space. Do you have any simple program???? Because I have to implement lot of concepts into it. (5 Replies)
Discussion started by: gokult
5 Replies

8. Homework & Coursework Questions

mmap

Descriptions: Develop a program that uses mmap() to map a file to memory space. Prepare such a file by yourself and do the follows. <LI class=MsoNormal>Display the content of the file after mapping; <LI class=MsoNormal>Output how many digits included in the file; <LI class=MsoNormal>Replace... (1 Reply)
Discussion started by: gokult
1 Replies

9. Programming

mmap

hai, How do we map 'n' number of files into memory by using mmap system call?? Thanks in advance...... (5 Replies)
Discussion started by: andrew.paul
5 Replies

10. Emergency UNIX and Linux Support

mmap

I want to know whether this is possile or ever been tried out. I want to obtain a chuck of memory using mmap() I do it so : n = mmap(0, 8000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); And hold on to that memory, when a process requests for memory, some memory is... (2 Replies)
Discussion started by: xerox
2 Replies
ZZIP_DISK_MMAP(3)					       zziplib Function List						 ZZIP_DISK_MMAP(3)

NAME
zzip_disk_mmap, zzip_disk_init, zzip_disk_new, zzip_disk_munmap, zzip_disk_open, zzip_disk_close - turn a filehandle into a mmapped zip disk archive handle SYNOPSIS
#include <zzip/mmapped.h> zzip__new__ ZZIP_DISK * zzip_disk_mmap((int fd)); int zzip_disk_init((ZZIP_DISK * disk, void *buffer, zzip_size_t buflen)); zzip__new__ ZZIP_DISK * zzip_disk_new((void)); int zzip_disk_munmap((ZZIP_DISK * disk)); ZZIP_DISK *zzip__new__ zzip_disk_open((char *filename)); int zzip_disk_close((ZZIP_DISK * disk)); DESCRIPTION
The zzip_disk_mmap function uses the given file-descriptor to detect the length of the file and calls the system mmap(2) to put it in main memory. If it is successful then a newly allocated ZZIP_DISK* is returned with disk->buffer pointing to the mapview of the zipdisk content. The zzip_disk_init function does primary initialization of a disk-buffer struct. The zzip_disk_new function allocates a new disk-buffer with malloc(3) The zzip_disk_munmap function is the inverse of zzip_disk_mmap and using the system munmap(2) on the buffer area and free(3) on the ZZIP_DISK structure. The zzip_disk_open function opens the given archive by name and turn the filehandle to zzip_disk_mmap for bringing it to main memory. If it can not be mmap(2)'ed then we slurp the whole file into a newly malloc(2)'ed memory block. Only if that fails too then we return null. Since handling of disk->buffer is ambigous it should not be snatched away please. The zzip_disk_close function will release all data needed to access a (mmapped) zip archive, including any malloc()ed blocks, sharedmem mappings and it dumps the handle struct as well. AUTHOR
o Guido Draheim <guidod@gmx.de> COPYRIGHT
Copyright (c) 2003,2004,2006 Guido Draheim All rights reserved, use under the restrictions of the Lesser GNU General Public License or alternatively the restrictions of the Mozilla Public License 1.1 zziplib 0.13.56 ZZIP_DISK_MMAP(3)
All times are GMT -4. The time now is 04:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy