Mac-Carbon

 view release on metacpan or  search on metacpan

Memory/Memory.xs  view on Meta::CPAN


Almost all of the memory management needs in MacPerl can be handled by the above interface

=cut

MODULE = Mac::Memory	PACKAGE = Ptr

=head2 Ptr

Ptr provides an object interface to do simple operations on MacOS pointers
(nonrelocatable heap blocks). There are very few good reasons to create pointers
like this.

=over 4

=cut

PtrRet
new(package,len)
	SV *	package
	long	len

Memory/Memory.xs  view on Meta::CPAN

=item NewPtrSys BYTECOUNT

B<Mac OS only.>

=item NewPtrClear BYTECOUNT

=item NewPtrSysClear BYTECOUNT

B<Mac OS only.> (NewPtrSys, NewPtrSysClear)

Allocate a nonrelocatable block of memory of a specified size.

NewPtrSys and NewPtrSysClear allocate blocks in the system heap.

NewPtrClear and NewPtrSysClear allocate and zero the blocks (inefficiently).


=cut
PtrRet
NewPtr(byteCount)
	long	byteCount

Memory/Memory.xs  view on Meta::CPAN


#else

HandleRet
NewEmptyHandleSys()

#endif

=item HLock HANDLE

Lock a relocatable block so that it does not move in the heap. If you plan to
dereference a handle and then allocate, move, or purge memory (or call a routine
that does so), then you should lock the handle before using the dereferenced
handle.


=cut
void
HLock(h)
	Handle	h
	CLEANUP:
	MemErrorReturn

=item HUnlock HANDLE

Unlock a relocatable block so that it is free to move in its heap zone.


=cut
void
HUnlock(h)
	Handle	h
	CLEANUP:
	MemErrorReturn

=item HPurge HANDLE

Mark a relocatable block so that it can be purged if a memory request cannot be
fulfilled after compaction.


=cut
void
HPurge(h)
	Handle	h
	CLEANUP:
	MemErrorReturn

=item HNoPurge HANDLE

Mark a relocatable block so that it cannot be purged.


=cut
void
HNoPurge(h)
	Handle	h
	CLEANUP:
	MemErrorReturn

=item HLockHi HANDLE

The HLockHi procedure attempts to move the relocatable block referenced by the
handle $HANDLE upward until it reaches a nonrelocatable block, a locked relocatable
block, or the top of the heap. Then HLockHi locks the block.


=cut
void
HLockHi(h)
	Handle	h
	CLEANUP:
	MemErrorReturn

Memory/Memory.xs  view on Meta::CPAN

		RETVAL = TempMaxMem(&grow);
	}
	OUTPUT:
	RETVAL

=item TempFreeMem

The TempFreeMem function returns the total amount of free temporary memory that
you could allocate by calling TempNewHandle. The returned value is the total
number of free bytes. Because these bytes might be dispersed throughout memory,
it is ordinarily not possible to allocate a single relocatable block of that
size.

    $SIZE = &TempFreeMem;


=cut
long
TempFreeMem()

=item CompactMem BYTECOUNT

=item CompactMemSys BYTECOUNT

B<Mac OS only.> (CompactMemSys)

The CompactMem function compacts the current heap zone by moving unlocked,
relocatable blocks down until they encounter nonrelocatable blocks or locked,
relocatable blocks, but not by purging blocks. It continues compacting until it
either finds a contiguous block of at least $BYTECOUNT free bytes or has compacted
the entire zone.

The CompactMem function returns the size, in bytes, of the largest contiguous
free block for which it could make room, but it does not actually allocate that
block.

CompactMemSys does the same for the system heap.


Memory/Memory.xs  view on Meta::CPAN

=item PurgeMemSys BYTECOUNT

B<Mac OS only.> (PurgeMemSys)

The PurgeMem procedure sequentially purges blocks from the current heap zone
until it either allocates a contiguous block of at least $BYTECOUNT free bytes or
has purged the entire zone. If it purges the entire zone without creating a
contiguous block of at least $BYTECOUNT free bytes, PurgeMem generates a
memFullErr.

The PurgeMem procedure purges only relocatable, unlocked, purgeable blocks.

The PurgeMem procedure does not actually attempt to allocate a block of  $BYTECOUNT
bytes.

PurgeMemSys does the same for the system heap.


=cut
void
PurgeMem(cbNeeded)

Memory/Memory.xs  view on Meta::CPAN

#endif

=item FreeMem

=item FreeMemSys

B<Mac OS only.> (FreeMemSys)

The FreeMem function returns the total amount of free space (in bytes) in the
current heap zone. Note that it usually isn't possible to allocate a block of
that size, because of heap fragmentation due to nonrelocatable or locked blocks.

FreeMemSys does the same for the system heap.


=cut
long
FreeMem()

#ifndef MACOS_TRADITIONAL

Memory/Memory.xs  view on Meta::CPAN


=item ReserveMem BYTECOUNT

=item ReserveMemSys BYTECOUNT

B<Mac OS only.> (ReserveMemSys)

The ReserveMem procedure attempts to create free space for a block of $BYTECOUNT
contiguous logical bytes at the lowest possible position in the current heap
zone. It pursues every available means of placing the block as close as possible
to the bottom of the zone, including moving other relocatable blocks upward,
expanding the zone (if possible), and purging blocks from it. 

ReserveMemSys does the same for the system heap.


=cut
void
ReserveMem(cbNeeded)
	long	cbNeeded

Memory/Memory.xs  view on Meta::CPAN

		
		XS_PUSH(long, MaxMemSys(&grow));
		if (GIMME == G_ARRAY) {
			XS_PUSH(long, grow);
		}
#endif
	}

=item MoveHHi HANDLE

The MoveHHi procedure attempts to move the relocatable block referenced by the
handle $HANDLE upward until it reaches a nonrelocatable block, a locked relocatable
block, or the top of the heap.


=cut
void
MoveHHi(h)
	Handle	h
	CLEANUP:
	MemErrorReturn

=item DisposePtr PTR

Releases the memory occupied by the nonrelocatable block specified by $PTR.


=cut
void
DisposePtr(p)
	Ptr	p
	CLEANUP:
	MemErrorReturn

=item GetPtrSize PTR

The GetPtrSize function returns the logical size, in bytes, of the nonrelocatable
block pointed to by $PTR.


=cut
long
GetPtrSize(p)
	Ptr	p
	CLEANUP:
	gMacPerl_OSErr = MemError();

=item SetPtrSize PTR, NEWSIZE

The SetPtrSize procedure attempts to change the logical size of the
nonrelocatable block pointed to by $PTR. The new logical size is specified by
$NEWSIZE.
Return zero if no error was detected.


=cut
void
SetPtrSize(p, newSize)
	Ptr	p
	long	newSize
	CLEANUP:
	MemErrorReturn

=item DisposeHandle HANDLE

The DisposeHandle procedure releases the memory occupied by the relocatable block
whose handle is $HANDLE. It also frees the handle's master pointer for other uses.


=cut
void
DisposeHandle(h)
	Handle	h
	CLEANUP:
	MemErrorReturn

=item SetHandleSize HANDLE, BYTECOUNT

The SetHandleSize procedure attempts to change the logical size of the
relocatable block whose handle is $HANDLE. The new logical size is specified by
$BYTECOUNT.
Return zero if no error was detected.


=cut
void
SetHandleSize(h, newSize)
	Handle	h
	long		newSize
	CLEANUP:
	MemErrorReturn

=item GetHandleSize HANDLE

The GetHandleSize function returns the logical size, in bytes, of the relocatable
block whose handle is $HANDLE. In case of an error, GetHandleSize returns 0.


=cut
long
GetHandleSize(h)
	Handle	h

=item ReallocateHandle HANDLE, BYTECOUNT

Allocates a new relocatable block with a logical size of $BYTECOUNT bytes. It
updates the handle $HANDLE by setting its master pointer to point to the new block. 
The new block is unlocked and unpurgeable.
Return zero if no error was detected.


=cut
void
ReallocateHandle(h, byteCount)
	Handle	h
	long		byteCount
	CLEANUP:
	MemErrorReturn

=item EmptyHandle

Free memory taken by a relocatable block without freeing the relocatable block's
master pointer for other uses.


=cut
void
EmptyHandle(h)
	Handle	h
	CLEANUP:
	MemErrorReturn

Memory/Memory.xs  view on Meta::CPAN

		long	contig;
	
		PurgeSpace(&total, &contig);
		EXTEND(sp, 2);
		PUSHs(sv_2mortal(newSViv(total)));
		PUSHs(sv_2mortal(newSViv(contig)));
	}	

=item HGetState HANDLE

Get the current properties of a relocatable block (perhaps so that you can change
and then later restore those properties).


=cut
char
HGetState(h)
	Handle	h
	CLEANUP:
	if (gMacPerl_OSErr = MemError())
		RETVAL = 0;

Memory/Memory.xs  view on Meta::CPAN

=cut
void
HSetState(h, flags)
	Handle	h
	char		flags
	CLEANUP:
	MemErrorReturn

=item HandToHand HANDLE

The HandToHand function attempts to copy the information in the relocatable block
to which $HANDLE is a handle.
Return C<undef> if an error was detected.


=cut
Handle
HandToHand(theHndl)
	Handle	&theHndl
	CODE:
	if (gMacPerl_OSErr = HandToHand(&theHndl)) {

Memory/Memory.xs  view on Meta::CPAN


=cut
MacOSRet
PtrToXHand(srcPtr, dstHndl, size)
	Ptr		srcPtr
	Handle	dstHndl
	long		size

=item HandAndHand AHNDLE, BHNDLE

The HandAndHand function concatenates the information from the relocatable block
to which $AHNDL is a handle onto the end of the relocatable block to which $BHNDL
is a handle. The $AHNDL variable remains unchanged.
Return zero if no error was detected.


=cut
MacOSRet
HandAndHand(hand1, hand2)
	Handle	hand1
	Handle	hand2
	CODE:

Memory/Memory.xs  view on Meta::CPAN

		RETVAL = HandAndHand(hand1, hand2);
		HSetState(hand1, state);
	}
	OUTPUT:
	RETVAL

=item PtrAndHand PTR, HANDLE, BYTECOUNT

The PtrAndHand function takes the number of bytes specified by $BYTECOUNT, 
beginning at the location specified by $PTR, and concatenates them
onto the end of the relocatable block to which $HANDLE is a handle.


=cut
MacOSRet
PtrAndHand(ptr1, hand2, size)
	Ptr		ptr1
	Handle	hand2
	long		size

=back



( run in 0.548 second using v1.01-cache-2.11-cpan-5511b514fd6 )