BBC BASIC for Windows
« [BB4WFORTH] Memory Allocation and thoughts... »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:02pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: [BB4WFORTH] Memory Allocation and thoughts...  (Read 572 times)
afarlie
New Member
Image


member is offline

Avatar




PM


Posts: 18
xx [BB4WFORTH] Memory Allocation and thoughts...
« Thread started on: Sep 25th, 2009, 12:05am »

At the end of this message is some sample code for doing memory allocations in BB4W.

It would be appreciated if someone was able to provide
a hint as to how COMPILE, and POSTPONE could be added
as there's some interesting code here
http://www.jwdt.com/~paysan/mini-oof.html

The code for Mini OOF could with translation might also
be of interest to anyone wanting to attempt OO in
BBCBASIC using structures and indirect PROC/FN calls


Alex Farlie

\ Memory Allocation words for BB4WFORTH

\ Allocation words...
\ These are wrappers around the equivlant Win32 API Functions
\ FIXME: ior is the Win32 error code at present - Somone might want to convert these to BB4W type error codes.


Z "KERNEL32.DLL" LoadLibrary
DUP Z" GetLastError" GetProcAddress CONSTANT 'GetLastError'
DUP Z" GlobalAlloc" GetProcAddress CONSTANT 'GlobalAlloc'
DUP Z" GlobalRealloc" GetProcAddress CONSTANT 'GlobalRealloc'
DUP Z" GlobalFree" GetProcAddress CONSTANT 'GlobalFree'
DROP

HEX
: _CHECK_HANDLE (handle -- handle ior)
DUP \Duplicate return value
=0 \ IS Null?
IF
'GetLastError' \ Get the last error value from Windows
SYSCALL
ELSE
0 \ Otherwise the IOR code is 0= Success!
THEN
;
: ALLOCATE (u -- handle ior) \ Allocate fixed memory
40 LITERAL \ GPTR Constant
SWAP \ Reorder for API call
'GlobalAlloc'
SYSCALL \Global alloc call
_CHECK_HANDLE


;
: FREE (a-addr -- ior)
'GlobalFree'
SYSCALL
_CHECK_HANDLE
SWAP DROP \ Don't want handle only want I/O code.
;

: RESIZE (a-addr u -- addr ior)
40 LITERAL \GMEM_ZEROINIT
'GlobalRealloc' \
SYSCALL
_CHECK HANDLE
;
DECIMAL

\ Hide WIN32 calls in favour of 'standard' words
HIDE 'GlobalAlloc'
HIDE 'GlobalRealloc'
HIDE 'GlobalFree'
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls