Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
BUFALLOC.C
Package: CRCSET13 [view]
Upload User: cuilin0620
Upload Date: 2007-01-13
Package Size: 33k
Code Size: 1k
Category:
Kill Virus
Development Platform:
C/C++
- /*
- BUFALLOC.C
- Kevin Dean
- Fairview Mall P.O. Box 55074
- 1800 Sheppard Avenue East
- Willowdale, Ontario
- CANADA M2J 5B9
- CompuServe ID: 76336,3114
- March 24, 1991
- This module allocates a simple memory buffer whose size depends on the
- amount of memory available. The size of the buffer is halved each time the
- allocation fails until memory is successfully allocated or the size goes below
- the minimum size requested.
- This code is public domain.
- */
- #include <stdlib.h>
- /***/
- /* Allocate a buffer of flexible size. */
- void *bufalloc(size_t *size, size_t minsize)
- {
- void *buffer; /* Buffer allocated. */
- size_t bufsize; /* Size of buffer allocated. */
- /* Allocate as big a buffer as possible (at least minsize). */
- for (bufsize = *size; bufsize >= minsize && !(buffer = malloc(bufsize)); bufsize /= 2);
- /* Save buffer size. */
- *size = bufsize;
- return (buffer);
- }