-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMacMemory.h
2531 lines (2322 loc) · 85.8 KB
/
MacMemory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
File: CarbonCore/MacMemory.h
Contains: Memory Manager Interfaces.
Version: CarbonCore-783~2
Copyright: © 1985-2006 by Apple Computer, Inc., all rights reserved
Bugs?: For bug reports, consult the following page on
the World Wide Web:
http://developer.apple.com/bugreporter/
*/
#ifndef __MACMEMORY__
#define __MACMEMORY__
#ifndef __MACTYPES__
#include <CarbonCore/MacTypes.h>
#endif
#ifndef __MIXEDMODE__
#include <CarbonCore/MixedMode.h>
#endif
#include <string.h>
#include <AvailabilityMacros.h>
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus
extern "C" {
#endif
#pragma pack(push, 2)
enum {
maxSize = 0x7FFFFFF0 /*the largest block possible*/
};
/*
If you define a macro named __MAC_OS_X_MEMORY_MANAGER_CLEAN__ with a non-zero value, then
some Memory Manager APIs will become inlined, minimal implementations. See the comments
below for more information about this.
*/
#ifndef __MAC_OS_X_MEMORY_MANAGER_CLEAN__
#define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 0
#endif /* !defined(__MAC_OS_X_MEMORY_MANAGER_CLEAN__) */
#if !__MAC_OS_X_MEMORY_MANAGER_CLEAN__
enum {
defaultPhysicalEntryCount = 8
};
enum {
/* values returned from the GetPageState function */
kPageInMemory = 0,
kPageOnDisk = 1,
kNotPaged = 2
};
enum {
/* masks for Zone->heapType field */
k32BitHeap = 1, /* valid in all Memory Managers */
kNewStyleHeap = 2, /* true if new Heap Manager is present */
kNewDebugHeap = 4 /* true if new Heap Manager is running in debug mode on this heap */
};
#endif /* !__MAC_OS_X_MEMORY_MANAGER_CLEAN__ */
/* bits for use with HGetState/HSetState*/
enum {
kHandleIsResourceBit = 5,
kHandlePurgeableBit = 6,
kHandleLockedBit = 7
};
/* masks for use with HGetState/HSetState*/
enum {
kHandleIsResourceMask = 0x20,
kHandlePurgeableMask = 0x40,
kHandleLockedMask = 0x80
};
#if !__LP64__
typedef CALLBACK_API( long , GrowZoneProcPtr )(Size cbNeeded);
typedef CALLBACK_API( void , PurgeProcPtr )(Handle blockToPurge);
typedef CALLBACK_API( void , UserFnProcPtr )(void * parameter);
typedef STACK_UPP_TYPE(GrowZoneProcPtr) GrowZoneUPP;
typedef STACK_UPP_TYPE(PurgeProcPtr) PurgeUPP;
typedef STACK_UPP_TYPE(UserFnProcPtr) UserFnUPP;
struct Zone {
Ptr bkLim;
Ptr purgePtr;
Ptr hFstFree;
long zcbFree;
GrowZoneUPP gzProc;
short moreMast;
short flags;
short cntRel;
short maxRel;
short cntNRel;
SInt8 heapType; /* previously "maxNRel", now holds flags (e.g. k32BitHeap)*/
SInt8 unused;
short cntEmpty;
short cntHandles;
long minCBFree;
PurgeUPP purgeProc;
Ptr sparePtr;
Ptr allocPtr;
short heapData;
};
typedef struct Zone Zone;
typedef Zone * THz;
typedef THz * THzPtr;
#if !__MAC_OS_X_MEMORY_MANAGER_CLEAN__
struct MemoryBlock {
void * address;
unsigned long count;
};
typedef struct MemoryBlock MemoryBlock;
struct LogicalToPhysicalTable {
MemoryBlock logical;
MemoryBlock physical[8];
};
typedef struct LogicalToPhysicalTable LogicalToPhysicalTable;
typedef short PageState;
typedef short StatusRegisterContents;
enum {
kVolumeVirtualMemoryInfoVersion1 = 1 /* first version of VolumeVirtualMemoryInfo*/
};
struct VolumeVirtualMemoryInfo {
PBVersion version; /* Input: Version of the VolumeVirtualMemoryInfo structure*/
SInt16 volumeRefNum; /* Input: volume reference number*/
Boolean inUse; /* output: true if volume is currently used for file mapping*/
UInt8 _fill;
UInt32 vmOptions; /* output: tells what volume can support (same as DriverGestaltVMOptionsResponse vmOptions bits in DriverGestalt)*/
/* end of kVolumeVirtualMemoryInfoVersion1 structure*/
};
typedef struct VolumeVirtualMemoryInfo VolumeVirtualMemoryInfo;
typedef VolumeVirtualMemoryInfo * VolumeVirtualMemoryInfoPtr;
#endif /* !__MAC_OS_X_MEMORY_MANAGER_CLEAN__ */
/*
* NewGrowZoneUPP()
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: available as macro/inline
*/
extern GrowZoneUPP
NewGrowZoneUPP(GrowZoneProcPtr userRoutine) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* NewPurgeUPP()
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: available as macro/inline
*/
extern PurgeUPP
NewPurgeUPP(PurgeProcPtr userRoutine) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* NewUserFnUPP()
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: available as macro/inline
*/
extern UserFnUPP
NewUserFnUPP(UserFnProcPtr userRoutine) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* DisposeGrowZoneUPP()
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: available as macro/inline
*/
extern void
DisposeGrowZoneUPP(GrowZoneUPP userUPP) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* DisposePurgeUPP()
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: available as macro/inline
*/
extern void
DisposePurgeUPP(PurgeUPP userUPP) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* DisposeUserFnUPP()
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: available as macro/inline
*/
extern void
DisposeUserFnUPP(UserFnUPP userUPP) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* InvokeGrowZoneUPP()
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: available as macro/inline
*/
extern long
InvokeGrowZoneUPP(
Size cbNeeded,
GrowZoneUPP userUPP) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* InvokePurgeUPP()
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: available as macro/inline
*/
extern void
InvokePurgeUPP(
Handle blockToPurge,
PurgeUPP userUPP) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* InvokeUserFnUPP()
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: available as macro/inline
*/
extern void
InvokeUserFnUPP(
void * parameter,
UserFnUPP userUPP) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
#if __MACH__
#ifdef __cplusplus
inline GrowZoneUPP NewGrowZoneUPP(GrowZoneProcPtr userRoutine) { return userRoutine; }
inline PurgeUPP NewPurgeUPP(PurgeProcPtr userRoutine) { return userRoutine; }
inline UserFnUPP NewUserFnUPP(UserFnProcPtr userRoutine) { return userRoutine; }
inline void DisposeGrowZoneUPP(GrowZoneUPP) { }
inline void DisposePurgeUPP(PurgeUPP) { }
inline void DisposeUserFnUPP(UserFnUPP) { }
inline long InvokeGrowZoneUPP(Size cbNeeded, GrowZoneUPP userUPP) { return (*userUPP)(cbNeeded); }
inline void InvokePurgeUPP(Handle blockToPurge, PurgeUPP userUPP) { (*userUPP)(blockToPurge); }
inline void InvokeUserFnUPP(void * parameter, UserFnUPP userUPP) { (*userUPP)(parameter); }
#else
#define NewGrowZoneUPP(userRoutine) ((GrowZoneUPP)userRoutine)
#define NewPurgeUPP(userRoutine) ((PurgeUPP)userRoutine)
#define NewUserFnUPP(userRoutine) ((UserFnUPP)userRoutine)
#define DisposeGrowZoneUPP(userUPP)
#define DisposePurgeUPP(userUPP)
#define DisposeUserFnUPP(userUPP)
#define InvokeGrowZoneUPP(cbNeeded, userUPP) (*userUPP)(cbNeeded)
#define InvokePurgeUPP(blockToPurge, userUPP) (*userUPP)(blockToPurge)
#define InvokeUserFnUPP(parameter, userUPP) (*userUPP)(parameter)
#endif
#endif
#endif /* !__LP64__ */
/*
* MemError()
*
* Summary:
* Determines if an applicationÕs last direct call to a Memory
* Manager function executed successfully.
*
* Discussion:
* MemError() yields the result code produced by the last Memory
* Manager function your application called directly, and resets
* MemError() to return noErr in the future. MemError() is useful
* during application debugging. You might also use MemError as one
* part of a memory-management scheme to identify instances in which
* the Memory Manager rejects overly large memory requests by
* returning the error code memFullErr.
*
* To view the result codes that MemError() can produce, see "Memory
* Manager Result Codes".
*
* Do not rely on MemError() as the only component of a
* memory-management scheme. For example, suppose you call NewHandle
* or NewPtr and receive the result code noErr, indicating that the
* Memory Manager was able to allocate sufficient memory. In this
* case, you have no guarantee that the allocation did not deplete
* your applicationÕs memory reserves to levels so low that simple
* operations might cause your application to crash. Instead of
* relying on MemError(), check before making a memory request that
* there is enough memory both to fulfill the request and to support
* essential operations.
*
* On Mac OS X 10.3 and later, the value of MemError() is kept for
* each thread; prior to Mac OS X 10.3. MemError() is global to the
* application. Because of this, and other problems, the Memory
* Manager APIs are not thread safe before Mac OS X 10.3.
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern OSErr
MemError(void) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
/*
* LMGetMemErr()
*
* Summary:
* Returns the result of the last Memory Manager function, without
* clearing the value like MemError() does.
*
* Discussion:
* LMGetMemErr yields the result code produced by the last Memory
* Manager function your application called directly. Unlike
* MemError(), this function does not reset the stored value, so
* subsequent calls to LMGetMemErr() will still return this value
* until the next Memory Manager routine is called or until
* MemError() is called to reset the value. LMGetMemErr is useful
* during application debugging. You might also use this value as
* one part of a memory-management scheme to identify instances in
* which the Memory Manager rejects overly large memory requests by
* returning the error code memFullErr.
*
* To view the result codes that MemError() can produce, see "Memory
* Manager Result Codes".
*
* Do not rely on MemError() as the only component of a
* memory-management scheme. For example, suppose you call NewHandle
* or NewPtr and receive the result code noErr, indicating that the
* Memory Manager was able to allocate sufficient memory. In this
* case, you have no guarantee that the allocation did not deplete
* your applicationÕs memory reserves to levels so low that simple
* operations might cause your application to crash. Instead of
* relying on MemError(), check before making a memory request that
* there is enough memory both to fulfill the request and to support
* essential operations.
*
* On Mac OS X 10.3 and later, the value of MemError() is kept for
* each thread; prior to Mac OS X 10.3 there was one global value of
* MemError() which all threads shared. Because of this, and other
* problems, the Memory Manager APIs are not thread safe before Mac
* OS X 10.3.
*
* Mac OS X threading:
* Not thread safe
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern SInt16
LMGetMemErr(void) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
/*
* LMSetMemErr()
*
* Summary:
* Set the value which will be returned by MemError()
*
* Discussion:
* User code shouldn't need to call this function, which is used to
* set the value which the next call to MemError() will return.
*
* Mac OS X threading:
* Not thread safe
*
* Parameters:
*
* value:
* the value which the next MemError() function call should return
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern void
LMSetMemErr(SInt16 value) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
/*
* NewHandle()
*
* Summary:
* Allocate a relocatable memory block of a specified size.
*
* Discussion:
* The NewHandle function attempts to allocate a new relocatable
* block in the current heap zone with a logical size of logicalSize
* bytes and then return a handle to the block. The new block is
* unlocked and unpurgeable. If NewHandle cannot allocate a block of
* the requested size, it returns NULL. The memory block returned
* likely will contain garbage, and will be unlocked and
* non-purgeable.
*
* WARNING
*
* Do not try to manufacture your own handles without this function
* by simply assigning the address of a variable of type Ptr to a
* variable of type Handle. The resulting "fake handle" would not
* reference a relocatable block and could cause a system crash.
* If this function returns NIL, the error result can be determined
* by calling the function MemError().
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Parameters:
*
* byteCount:
* the size of the relocatable memory block to allocate. If this
* value is < 0, NIL will be returned. If this value is 0, a
* handle to 0 byte block will be returned.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern Handle
NewHandle(Size byteCount) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
/*
* NewHandleClear()
*
* Summary:
* Allocate a relocatable memory block of a specified size.
*
* Discussion:
* The NewHandle function attempts to allocate a new relocatable
* block in the current heap zone with a logical size of logicalSize
* bytes and then return a handle to the block. The new block is
* unlocked and unpurgeable. If NewHandle cannot allocate a block of
* the requested size, it returns NULL. The memory block returned
* will be zeroed, and will be unlocked and non-purgeable.
*
* WARNING
*
* Do not try to manufacture your own handles without this function
* by simply assigning the address of a variable of type Ptr to a
* variable of type Handle. The resulting "fake handle" would not
* reference a relocatable block and could cause a system crash.
* If this function returns NIL, the error result can be determined
* by calling the function MemError().
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Parameters:
*
* byteCount:
* the size of the relocatable memory block to allocate. If this
* value is < 0, NIL will be returned. If this value is 0, a
* handle to 0 byte block will be returned.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern Handle
NewHandleClear(Size byteCount) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
/*
* RecoverHandle()
*
* Summary:
* Returns a handle to a relocatable block pointed to by a specified
* pointer.
*
* Discussion:
* The Memory Manager does not allow you to change relocatable
* blocks into nonrelocatable blocks, or vice-versa. However, if you
* no longer have access to a handle but still have access to its
* master pointer p, you can use the RecoverHandle function to
* recreate a handle to the relocatable block referenced by
* p.
*
* Call the function MemError() to get the result code. See "Memory
* Manager Result Codes".
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Parameters:
*
* p:
* the master pointer to a relocatable block.
*
* Result:
* A handle to a relocatable block point to by p. If p does not
* point to a valid block, this function returns NULL.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern Handle
RecoverHandle(Ptr p) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
/*
* NewPtr()
*
* Summary:
* Allocates a nonrelocatable block of memory of a specified size.
*
* Discussion:
* The NewPtr function attempts to reserve space for the new block.
* If it is able to reserve the requested amount of space, NewPtr
* allocates the nonrelocatable block. Otherwise, NewPtr returns
* NULL and generates a memFullErr error. On Mac OS X, NewPtr will
* never fail because it is unable to allocate the pointer. Certain
* old versions of Mac OS X return a NULL pointer when asked to
* allocate a pointer of size 0.
* Call the function MemError to get the result code. See "Memory
* Manager Result Codes".
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Parameters:
*
* byteCount:
* The requested size (in bytes) of the nonrelocatable block. If
* you pass a value of zero, this function returns a valid zero
* length pointer.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern Ptr
NewPtr(Size byteCount) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
/*
* NewPtrClear()
*
* Summary:
* Allocates a nonrelocatable block of memory of a specified size
* with all its bytes set to 0.
*
* Discussion:
* The NewPtr function attempts to reserve space for the new block.
* If it is able to reserve the requested amount of space, NewPtr
* allocates the nonrelocatable block. Otherwise, NewPtr returns
* NULL and generates a memFullErr error. On Mac OS X, NewPtr will
* never fail because it is unable to allocate the pointer. Certain
* old versions of Mac OS X return a NULL pointer when asked to
* allocate a pointer of size 0.
* Call the function MemError to get the result code. See "Memory
* Manager Result Codes".
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Parameters:
*
* byteCount:
* The requested size (in bytes) of the nonrelocatable block. If
* you pass a value of zero, this function returns a valid zero
* length pointer.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern Ptr
NewPtrClear(Size byteCount) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
#if !__LP64__
/*
* MaxBlock() *** DEPRECATED ***
*
* Summary:
* Return the size of the largest block you could allocate in the
* current heap zone after compaction.
*
* Discussion:
* On Mac OS X, this function always returns a large value, because
* virtual memory is always available to fulfill any request for
* memory. This function is deprecated on Mac OS X and later. You
* can assume that any reasonable memory allocation will succeed.
*
* Mac OS X threading:
* Not thread safe
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern long
MaxBlock(void) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5;
/*
* StackSpace() *** DEPRECATED ***
*
* Summary:
* Returns the amount of space unused on the current thread's stack.
*
* Mac OS X threading:
* Not thread safe
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern long
StackSpace(void) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5;
#endif /* !__LP64__ */
/*
* NewEmptyHandle()
*
* Summary:
* Initializes a new handle without allocating any memory for it to
* control.
*
* Discussion:
* When you want to allocate memory for the empty handle, use the
* ReallocateHandle function.
* Call the function MemError to get the result code. See "Memory
* Manager Result Codes".
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern Handle
NewEmptyHandle(void) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
/*
* HLock()
*
* Summary:
* Lock a relocatable block so that it does not move in the heap
*
* Discussion:
* The HLock procedure locks the relocatable block to which h is a
* handle, preventing it from being moved within its heap zone. If
* the block is already locked,HLock does nothing.
*
* On Mac OS X, the behaviour of the Memory Manager and of heaps in
* general is different than on Mac OS 9.x and earlier. In
* particular, the heap on Mac OS X is never purged or compacted.
* Therefore, an unlocked handle will never be relocated except as a
* result of a direct action by something calling SetHandleSize() or
* by using a function like PtrAndHand() which implicitly resizes
* the handle to append data to it. Because of this, most locking
* and unlocking of handles is unnecessary on Mac OS X, and the use
* of HLock() and other functions is being deprecated. If you
* define a macro named __MAC_OS_X_MEMORY_MANAGER_CLEAN__ to 1 in
* your sources before you include MacMemory.h, then HLock() and
* several other functions will become empty operations, removing
* the overhead of a function call.
*
* However, some applications are relying on the behavior that
* resizing a locked handle produces an error, or tracking the state
* of the locked bit for a give handle via the HGetState() function.
* Applications which rely on this can not use
* __MAC_OS_X_MEMORY_MANAGER_CLEAN__.
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Parameters:
*
* h:
* the handle to lock. If h is == NULL, then HLock() sets
* MemError() to noErr.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern void
HLock(Handle h) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
/*
* HLockHi()
*
* Summary:
* Lock a relocatable handle.
*
* Discussion:
* The HLockHi() function locks a handle in memory. On versions of
* Mac OS before Mac OS X, it would first attempt to move the handle
* as high in memory as feasible. However, on Mac OS X and later,
* there is no advantage to having handles high in memory, and so
* this function never moves a handle before locking it.
* See the discussion about handle locking above the function
* HLock().
*
* Mac OS X threading:
* Not thread safe
*
* Parameters:
*
* h:
* the handle to lock. If h is == NULL, then HLockHi() sets
* MemError() to noErr.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern void
HLockHi(Handle h) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
/*
* HUnlock()
*
* Summary:
* Unlock a relocatable block so that it does not move in the heap
*
* Discussion:
* The HUnlock procedure unlocks the relocatable block to which h is
* a handle, allowing it from being moved within its heap zone. If
* the block is already unlocked, HUnlock does nothing.
*
* See the discussion about handles and locking on Mac OS X above
* the HLock() function.
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Parameters:
*
* h:
* the handle to unlock. If h is == NULL, then HUnlock() sets
* MemError() to noErr.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern void
HUnlock(Handle h) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
#if !__LP64__
/*
* HPurge() *** DEPRECATED ***
*
* Summary:
* Mark a relocatable block so that it does can be purged if a
* memory request cannot be fulfilled after compaction of the heap
*
* Discussion:
* The HPurge procedure makes the relocatable block to which h is a
* handle purgeable. If the block is already purgeable, HPurge does
* nothing.
*
* On Mac OS X, heaps are never purged. Therefore, the use of
* HPurge() and its associated functios is deprecated. If you define
* a macro __MAC_OS_X_MEMORY_MANAGER_CLEAN__ in your sources before
* you include MacMemory.h, then any calls to HPurge() in your
* program will essentially be removed.
*
* However, some applications may set the handle as purgeable, and
* then later check the purgeBit for the handle via HGetState(). If
* your application depends on the purge bit being set for handles,
* you will not be able to take advantage of this macro.
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Parameters:
*
* h:
* the handle to mark as purgeable. If h is == NULL, then
* HPurge() just sets MemError() to noErr.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.4
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern void
HPurge(Handle h) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* HNoPurge() *** DEPRECATED ***
*
* Summary:
* Mark a relocatable block so that it can not be purged.
*
* Discussion:
* The HNoPurge procedure makes the relocatable block to which h is
* a handle unpurgeable. See the discussion about purgable handles
* above the HPurge() function.
*
* Mac OS X threading:
* Thread safe since version 10.3
*
* Parameters:
*
* h:
* the handle to mark as nonpurgeable. If h is == NULL, then
* HPurge() just sets MemError() to noErr.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.4
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern void
HNoPurge(Handle h) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
#endif /* !__LP64__ */
/*
* TempNewHandle()
*
* Summary:
* Allocate a relocatable memory block of a specified size.
*
* Discussion:
* The TempNewHandle function attempts to allocate a new relocatable
* block in the current heap zone with a logical size of logicalSize
* bytes and then return a handle to the block. The new block is
* unlocked and unpurgeable. If NewHandle cannot allocate a block of
* the requested size, it returns NULL. The memory block returned
* likely will contain garbage.
*
* WARNING
*
* Do not try to manufacture your own handles without this function
* by simply assigning the address of a variable of type Ptr to a
* variable of type Handle. The resulting "fake handle" would not
* reference a relocatable block and could cause a system crash.
* If this function returns NIL, the error result can be determined
* by calling the function MemError().
*
* On Mac OS X, there is no temporary memory heap, and thus no
* difference between the handles returned by TempNewHandle() and
* those returned by NewHandle(). The only difference between the
* two is that TempNewHandle() also returns the error result of the
* call in resultCode.
*
* Mac OS X threading:
* Not thread safe
*
* Parameters:
*
* logicalSize:
* the size of the relocatable memory block to allocate. If this
* value is < 0, NIL will be returned. If this value is 0, a
* handle to 0 byte block will be returned.
*
* resultCode:
* On exit, this will be set to the result of the operation.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern Handle
TempNewHandle(
Size logicalSize,
OSErr * resultCode) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;
#if !__LP64__
/*
* TempMaxMem() *** DEPRECATED ***
*
* Summary:
* Return the maximum amount of temporary memory available
*
* Discussion:
* On Mac OS X, this function always returns a large value, because
* virtual memory is always available to fulfill any request for
* memory. This function is deprecated on Mac OS X and later. You
* can assume that any reasonable memory allocation will succeed.
*
* Mac OS X threading:
* Not thread safe
*
* Parameters:
*
* grow:
* If != NULL, then this is filled in with the the value 0.
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.4
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern Size
TempMaxMem(Size * grow) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* TempFreeMem() *** DEPRECATED ***
*
* Summary:
* Return the maximum amount of free memory in the temporary heap.
*
* Discussion:
* On Mac OS X, there is no separate temporary memory heap. This
* function always returns a large value, because virtual memory is
* always available to fulfill any request for memory. This
* function is deprecated on Mac OS X and later. You can assume
* that any reasonable memory allocation will succeed.
*
* Mac OS X threading:
* Not thread safe
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.4
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern long
TempFreeMem(void) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* CompactMem() *** DEPRECATED ***
*
* Summary:
* Compact the heap by purging and moving blocks such that at least
* cbNeeded bytes are available, if possible.
*
* Discussion:
* On Mac OS X and later, blocks are never purged and memory heaps
* will grow as necessary, so compaction is never necessary nor
* performed.
*
* Mac OS X threading:
* Not thread safe
*
* Availability:
* Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.4
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/
extern Size
CompactMem(Size cbNeeded) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
/*
* PurgeMem() *** DEPRECATED ***
*
* Summary:
* Purge blocks from the heap until cbNeeded bytes are available, if