home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / c1 / c_impress / Sources / Heap < prev    next >
Encoding:
Text File  |  1991-04-08  |  5.4 KB  |  2 lines

  1. 4&:ô  ><BasicV$Lib>.Heap         Wimp heap manager. v0.0840ô  MACHINE:  Archimedes4:ô  LANGUAGE: BBC BASIC V4Dô  AUTHOR:   Cy Booker,4NGô            86 Church View, Main Road, Crockenhill, Swanley, Kent.4Xô            BR8 8JW4bô  FUNCTIONS:4l!ô   Claim_Heap_Block( size% )4v0ô   XClaim_Heap_Block( RETURN addr%, size% )4€+ô   XRelease_Heap_Block( RETURN addr% )4⇩3ô   XExtend_Heap_Block( d_size%, RETURN addr% )4“ô   XExtend_Heap()4fiô  :4¨ô  PROCEDURES:4²/ô   Claim_Heap_Block( RETURN addr%, size% )4¼*ô   Release_Heap_Block( RETURN addr% )4Æô   Kill_Heap()4Ðô  :4Úô  EXTERNALS:4äô   <BasicV$Dir>.Wimp4îô  :4øô  VARIABLES:5<ô   Heap_Error%  == Error number when generate an error.5 ô  :5ô  UPDATES:5 4ô   16.03.1991 CJB FN_XExtend_Heap syntax error!5*%ô   17.03.1991 CJB PROC_Kill_Heap54:ô   19.03.1991 CJB FN_XExtend_Heap, non-local result%!5>Jô   30.03.1991 CJB XRelease_Heap_Block, non-local c%, XExtend_Heap, so5HLô                  should handle 1Mbyte machines, Kill_Heap, non-locals.5RLô                  When release block, trys and reduces heap/appl' size.5\'ô   05.04.1991 CJB Library version.5fIô   08.04.1991 CJB FN_XExtend_Heap_Block, now claims if zero address.5gLô   08.04.1991 CJB PROC_Try_Reducing_Heap demonstrated a bug in OS_Heap,5hDô                  which I got round by doing some extra checks.5p:5zC: ô  In this version, all parameters are absolute (application)5☓G: ô  addresses, since the actual heap is always going to be static.5‰:5—:5¢Ý ¤_Heap_version  :  = 0085¬:5¶Ý ¤_hard_initialise_Heap5Àê r0%, c%5Êê Ŷ5Ô7î Ŷ ê ÷ Ŷ  :  ò_e( "%.Heap: hard_initialise_Heap" )5Þ0  ò_load_library( "<BasicV$Lib>.Wimp", 001 )5è  Heap_Start% = ›5ò  Heap_Size%  = 32 * 10245ü  Heap_Error% = &90064  È− "Wimp_SlotSize", -1, -1 ¸ Application_Size%6  Application_Size% = ›6G  È− "XWimp_SlotSize", Application_Size% + Heap_Size%, -1 ¸ r0%; c%6$  ç ¤_PSR_V_set(c%) …6.A     Ŷ Heap_Error%, "Not enough memory to start application."68  Í6B:  È− "OS_Heap", 0, Heap_Start%, Heap_Size%, Heap_Size%6L= 06V:6`!Ý ¤_Claim_Heap_Block( size% )6jê result%6t/  ç ¤_XClaim_Heap_Block( result%, size% ) …6~C    ò_Wimp_Error( 0, "Not enough memory to claim heap block." )6⇦  Í6‹= result%6†:6¦>: ô  Returns Address of a claimed block, TRUE if couldn't.6°+: ô  Tries extending heap if necessary.6Ä:6Î+Ý ¤_XClaim_Heap_Block( ø addr%, size% )6Øê result%, heap_full%, c%6â  result%    = ¹6ì  heap_full% = £6ö  addr%      = 07  õ7
  2. <    È− "XOS_Heap", 2, Heap_Start%,, size% ¸ ,, addr%; c%7    ç ¤_PSR_V_set(c%) …7%      heap_full% = ¤_XExtend_Heap7(        Ì72      result% = £7<        Í7F  ý heap_full% ☓ ¬(result%)7P= result% ☓ heap_full%7Z:7´*Ý ò_Claim_Heap_Block( ø addr%, size% )7¾)  addr% = ¤_Claim_Heap_Block( size% )7Èá7Ò:7Ü.: ô  An error is generated if bad pointer.7æ%: ô  On exit, address reset to 0.7ð:7ú%Ý ò_Release_Heap_Block( ø addr% )8ê r0%, c%8  ç addr%<>0 …86    È− "XOS_Heap", 3, Heap_Start%, addr% ¸ r0%; c%8"    ç ¤_PSR_V_set(c%) …8,D      Ŷ Heap_Error%, "Bad Release_Heap_Block: "+ ¤getname(r0%+4)86        Í8@    addr% = 08J    ò_Try_Reducing_Heap8T  Í8^á8h:8r&Ý ¤_XRelease_Heap_Block( ø addr% )8|ê c%8ŷ  ç addr%<>0 …8‘3    È− "XOS_Heap", 3, Heap_Start%, addr% ¸ ; c%8Œ    ç ¬(¤_PSR_V_set(c%)) …8¤      addr% = 08®    ò_Try_Reducing_Heap8¸        Í8  Í8Ì= (addr% <> 0)8Ö:8àJ: ô  Returns TRUE if no can do.  NB would have tried extending heap as8ê6: ô  well.  Also note that addr% MAY have changed!8ô:8þ.Ý ¤_XExtend_Heap_Block( d_size%, ø addr% )9"ê result%, heap_full%, r0%, c%9  ç addr%=0 …97    result% = ¤_XClaim_Heap_Block( addr%, d_size% )9&  Ì90    result%    = ¹9:    heap_full% = £9D        õ9NI      È− "XOS_Heap", 4, Heap_Start%, addr%, d_size% ¸ r0%,, addr%; c%9X      ç ¤_PSR_V_set(c%) …9b'        heap_full% = ¤_XExtend_Heap9l       Ì9v        result% = £9€       Í9⇩!    ý heap_full% ☓ ¬(result%)9“  Í9fi= result%9¨:9²Ý ¤_XExtend_Heap9¼ ê heap_full%, r0%, c%, base%9Æ,  base% = Application_Size% + Heap_Size%9Ð<  È− "XWimp_SlotSize", base% + (32 * 1024), -1 ¸ r0%; c%9Ú3  heap_full% = (¤_PSR_V_set(c%) ☓ (r0%<=base%))9ä  ç ¬(heap_full%) …9î!    Heap_Size% += r0% - base%9ø2    È− "OS_Heap", 5, Heap_Start%,, r0% - base%:  Í: = heap_full%::: .: ô  Unconditionally kill off entire heap.:*E: ô  This is a quick and dirty bodge, should insist that all heap:40: ô  blocks have been released beforehand...:>::HÝ ò_Kill_Heap:Rê r0%, c%:\:  È− "XWimp_SlotSize", Application_Size%, -1 ¸ r0%; c%:f  ç ¤_PSR_V_set(c%) …:p1    Ŷ Heap_Error%, "Fatally bad heap murder.":z  Í:☓á:‰::—J: ô  This should be called after every release of a heap block, to see:¢L: ô  if can reduce the amount of memory the application is claiming from:¬: ô  the system.:¶G: ô  Error in OS_Heap 5, if try and reduce stack by more than total:À(: ô  free, then corrupts stack info.:Ê::ÔÝ ò_Try_Reducing_Heap:Þê free%, c%:è.  È− "OS_Heap", 1, Heap_Start% ¸ ,,, free%:ò  È” free%>(32 * 1024):ü;    È− "XOS_Heap", 5, Heap_Start%,, -(32 * 1024) ¸ ; c%;    ç ¬(¤_PSR_V_set(c%));!      Heap_Size% -= 32 * 1024;)      È− "Wimp_SlotSize", -1, -1 ¸ c%;$@      È− "Wimp_SlotSize", Application_Size% + Heap_Size%, -1;.2      È− "OS_Heap", 1, Heap_Start% ¸ ,,, free%;8        Ì;B      free% = 0;L        Í;V  Î;`á;j:;t$ô Last line of <BasicV$Lib>.Heapÿ