VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prmem.h@ 2988

Last change on this file since 2988 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/*
39** File: prmem.h
40** Description: API to NSPR 2.0 memory management functions
41**
42*/
43#ifndef prmem_h___
44#define prmem_h___
45
46#include "prtypes.h"
47#include <stddef.h>
48#include <stdlib.h>
49
50PR_BEGIN_EXTERN_C
51
52/*
53** Thread safe memory allocation.
54**
55** NOTE: pr wraps up malloc, free, calloc, realloc so they are already
56** thread safe (and are not declared here - look in stdlib.h).
57*/
58
59/*
60** PR_Malloc, PR_Calloc, PR_Realloc, and PR_Free have the same signatures
61** as their libc equivalent malloc, calloc, realloc, and free, and have
62** the same semantics. (Note that the argument type size_t is replaced
63** by PRUint32.) Memory allocated by PR_Malloc, PR_Calloc, or PR_Realloc
64** must be freed by PR_Free.
65*/
66
67NSPR_API(void *) PR_Malloc(PRUint32 size);
68
69NSPR_API(void *) PR_Calloc(PRUint32 nelem, PRUint32 elsize);
70
71NSPR_API(void *) PR_Realloc(void *ptr, PRUint32 size);
72
73NSPR_API(void) PR_Free(void *ptr);
74
75/*
76** The following are some convenience macros defined in terms of
77** PR_Malloc, PR_Calloc, PR_Realloc, and PR_Free.
78*/
79
80/***********************************************************************
81** FUNCTION: PR_MALLOC()
82** DESCRIPTION:
83** PR_NEW() allocates an untyped item of size _size from the heap.
84** INPUTS: _size: size in bytes of item to be allocated
85** OUTPUTS: untyped pointer to the node allocated
86** RETURN: pointer to node or error returned from malloc().
87***********************************************************************/
88#define PR_MALLOC(_bytes) (PR_Malloc((_bytes)))
89
90/***********************************************************************
91** FUNCTION: PR_NEW()
92** DESCRIPTION:
93** PR_NEW() allocates an item of type _struct from the heap.
94** INPUTS: _struct: a data type
95** OUTPUTS: pointer to _struct
96** RETURN: pointer to _struct or error returns from malloc().
97***********************************************************************/
98#define PR_NEW(_struct) ((_struct *) PR_MALLOC(sizeof(_struct)))
99
100/***********************************************************************
101** FUNCTION: PR_REALLOC()
102** DESCRIPTION:
103** PR_REALLOC() re-allocates _ptr bytes from the heap as a _size
104** untyped item.
105** INPUTS: _ptr: pointer to node to reallocate
106** _size: size of node to allocate
107** OUTPUTS: pointer to node allocated
108** RETURN: pointer to node allocated
109***********************************************************************/
110#define PR_REALLOC(_ptr, _size) (PR_Realloc((_ptr), (_size)))
111
112/***********************************************************************
113** FUNCTION: PR_CALLOC()
114** DESCRIPTION:
115** PR_CALLOC() allocates a _size bytes untyped item from the heap
116** and sets the allocated memory to all 0x00.
117** INPUTS: _size: size of node to allocate
118** OUTPUTS: pointer to node allocated
119** RETURN: pointer to node allocated
120***********************************************************************/
121#define PR_CALLOC(_size) (PR_Calloc(1, (_size)))
122
123/***********************************************************************
124** FUNCTION: PR_NEWZAP()
125** DESCRIPTION:
126** PR_NEWZAP() allocates an item of type _struct from the heap
127** and sets the allocated memory to all 0x00.
128** INPUTS: _struct: a data type
129** OUTPUTS: pointer to _struct
130** RETURN: pointer to _struct
131***********************************************************************/
132#define PR_NEWZAP(_struct) ((_struct*)PR_Calloc(1, sizeof(_struct)))
133
134/***********************************************************************
135** FUNCTION: PR_DELETE()
136** DESCRIPTION:
137** PR_DELETE() unallocates an object previosly allocated via PR_NEW()
138** or PR_NEWZAP() to the heap.
139** INPUTS: pointer to previously allocated object
140** OUTPUTS: the referenced object is returned to the heap
141** RETURN: void
142***********************************************************************/
143#define PR_DELETE(_ptr) { PR_Free(_ptr); (_ptr) = NULL; }
144
145/***********************************************************************
146** FUNCTION: PR_FREEIF()
147** DESCRIPTION:
148** PR_FREEIF() conditionally unallocates an object previously allocated
149** vial PR_NEW() or PR_NEWZAP(). If the pointer to the object is
150** equal to zero (0), the object is not released.
151** INPUTS: pointer to previously allocated object
152** OUTPUTS: the referenced object is conditionally returned to the heap
153** RETURN: void
154***********************************************************************/
155#define PR_FREEIF(_ptr) if (_ptr) PR_DELETE(_ptr)
156
157PR_END_EXTERN_C
158
159#endif /* prmem_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette