PHF Logo

PHF Consultancy


Development | Consultancy | Training

www Search this site
Powered by
Google
Home

Email

BookMark
Home Contact Us Products Services Technology How To... Partners Other Links

How to concatenate two dynamic memory segments (All Platforms)

 

There is a limitation within Synergy DBL regarding the maximum size of an argument. This limit is 64K
This is not normally a problem however when working with dynamic memory, sometimes you need to merge or concatenate large memory segments

So here is an example of a routine to add / concatenate to two dynamic memory segments. The first dynamic memory handle is resized and to hold the result and must be created as with the option DM_STATIC
The code can be download from here

.subroutine concat_dynmem, stack
    a_hdl1    ,n    ;mem handle 1
    a_hdl2    ,n    ;mem handle 2

;max size of data to move
.define MAX64K    ,65535

.align
record
    datasize    ,i4
    datapos    ,i4
    frompos    ,i4

structure dyndata
    dynchar    ,a1

.proc
    ;get this size of the two data areas
    datapos = %mem_proc(DM_GETSIZE, a_hdl1)
    datasize = %mem_proc(DM_GETSIZE, a_hdl2)

    ;resize first memory segment to hold result
    a_hdl1 = %mem_proc(DM_RESIZ, datapos + datasize, a_hdl1)

    frompos = 1
    repeat
        begin
        if (datasize .le. MAX64K)    ;less than 64k left
        exitloop

        ;move memory in 64K chunks
        ^m(dyndata[1].dynchar(datapos+1:max64k), a_hdl1) =
        &    ^m(dyndata[1].dynchar(frompos:max64k), a_hdl2)
        datasize = datasize - MAX64K
        datapos = datapos + MAX64K
        frompos = frompos + MAX64K
        end

    ;move the remaining memory
    if (datasize)
        ^m(dyndata[1].dynchar(datapos+1:datasize), a_hdl1) =
        &    ^m(dyndata[1].dynchar(frompos:datasize), a_hdl2)
    xreturn
.end


Referencing a chunk of dynamic memory larger than 64K results in one of to runtime errors depending on what you are doing.
Either a 'MAP outside bounds of field or handle' or 'Invalid Subscript specified'.


If you have any comments on this code. Please let me know.


Note: Synergy DBL Version 7 or higher required.

 

Valid HTML 4.01! Privacy Policy

Copyright © 1999-2007 PHF Consultancy
Banner images are trademarks of the companies represented