Need to access resources without copying the data.
Author |
Message |
N #1 / 17
|
Need to access resources without copying the data.
I need: Dim s As String Ptr * nnn How? Ordinary String ptr on a resource GPF's, the length is unknown, how to set so that i can use Instr()? PB/DLL60 Thanks,
|
Wed, 03 Sep 2003 02:46:31 GMT |
|
|
Michael Mattia #2 / 17
|
Need to access resources without copying the data.
Working Code lifted from one of my programs for a "user-defined" resource: szResName = "MAP4A01" : szResType = "EDIMAP" hFindRes =FindResource (hDllInst, szResName, szResType) IF ISTRUE (HFindRes) THEN nMapItems = SizeOfResource (hDllInst, hFindRes) \ SIZEOF (Dummy) hres = LoadResource (hDllInst,hFIndRes) IF ISTRUE (hRes) THEN ' lock the resource to get a pointer to it.. pMap = LockResource (hRes) <<< THIS IS THE POINTER TO THE RESOURCE To do an INSTR equivalent, adding to above code.... DIM pB AS BYTE PTR ' ( or STRING * nnn PTR where nnn= size of target string) pb = pMap << point your scan string at the start of the resource FOR I = 1 TO ResourceSize - sizeof(target)
found target, act accoringingly EXIT FOR ELSE INCR pB <<< if the search string is size greater than one, use pb= pb + 1, not incr, 'cuz incr increments by size of target END IF NEXT I LoadResource SizeOfResource LockResource <<< returns a pointer if succesful In your case, s = LockResource(LoadResource -- Michael Mattias Tal Systems Racine WI USA
Quote: > I need: > Dim s As String Ptr * nnn > How? > Ordinary String ptr on a resource GPF's, the length is unknown, how to set > so that i can use Instr()? > PB/DLL60 > Thanks,
|
Wed, 03 Sep 2003 21:13:32 GMT |
|
|
N #3 / 17
|
Need to access resources without copying the data.
An ordinary compare with Peek$ might do, i think it's slow. A few times i requested for a similar instr() but then in ASM. No response to that one yet.. Thanks,
|
Thu, 04 Sep 2003 03:01:13 GMT |
|
|
Lance Edmon #4 / 17
|
Need to access resources without copying the data.
If you dont know the length at compile time, then you can't create a fixed-length string pointer, If you are reading data from a string table, then there are other approaches, however, in this case, I'd suggest you use PEEK$(), or BYTE PTR's, etc, and dynamically build the variable-length data from scratch. However, if the data is zero-terminated strings, then you could use an ASCIIZ PTR. Other than that, you'll probably need to give us more information on _exactly_ what you are trying to achieve, in terms of the type of resource data, etc. Quote:
>I need: >Dim s As String Ptr * nnn >How? >Ordinary String ptr on a resource GPF's, the length is unknown, how to set >so that i can use Instr()? >PB/DLL60 >Thanks,
Lance powerbasic Support ------------------------------------------------------------------------- PowerBASIC, Inc. | 800-780-7707 Sales | "We put the Power in Basic!" 316 Mid Valley Center | 831-659-8000 Voice | http://www.powerbasic.com
|
Thu, 04 Sep 2003 13:36:32 GMT |
|
|
N #5 / 17
|
Need to access resources without copying the data.
I have a string in the resource as RCDATA. The string contains multiple chr$( 0 )'s therefore not handy to use asciiz. I would like to use this memory (lockResource) directly instead of copying it to a PB declared string. I do this stuff a lot and allways using a copy first. (Peek$ etc..) The only thing i (really) need is a instr() function which can make use of a memory pointer and the length. I can use a for next loop but this is very slow i think. I wish PB would had more options to use memory handles directly instead of making things local to PB first. And, not to forget, Array Scan using a memory handly instead of local defined array. I know my resource data of course but it's not fixed, an instr would be suficient for these matters. (No fixed record lengths)
|
Fri, 05 Sep 2003 04:54:09 GMT |
|
|
N #6 / 17
|
Need to access resources without copying the data.
Btw i did a dirty trick but it did work. A string ptr to the lockresource address and mem-4 set to the correct length. In practice worthless of course, it might be memory from another variable!
|
Fri, 05 Sep 2003 04:56:24 GMT |
|
|
N #7 / 17
|
Need to access resources without copying the data.
The following is JUST an example for discussion of instr() #define MYLIST_MAXNAMES 4 MYLIST RCDATA { MYLIST_MAXNAMES // Ammount of Records. , 1L, "String1\0" , 2L, "String2\0" , 3L, "String3\0" , 4L, "String4\0" Quote: }
Suppose i would like to use: a = Instr( pMem + 4, MkL$( 3 ), LenOfResoure& ) These string functions are not possible unf. 2 years ago i spoke to you about the returned data from a PB internal funtion like PEEK$() You didn't understand me very well at that time but let me try again. I may assume PEEK$() will ALREADY have made a copy IN PB memory on execution of PEEK$() So, Dim T AS String T = Peek$( pMem, 100000 ) will lead to have the same data 3x in memory by now. the original, Peek$(), and T Sure, when going out of scope, 2 memories will be lost in this example. I would like to use the original memory directly. Suppose i have data > 200mb or sort of.. (will not happen) If Peek$() would return an internal management 'handle' i could use: a = Instr( Peek$( pMem + 4, 100000 ), MkL$( 3 ) ) ) As i see it, the data is now 2x in memory, still not desired. Am i wrong? (I wonder, if Peek$() has a valid strptr, gonna check this one)
|
Fri, 05 Sep 2003 05:31:17 GMT |
|
|
Lance Edmon #8 / 17
|
Need to access resources without copying the data.
Quote:
>I may assume PEEK$() will ALREADY have made a copy IN PB memory on execution >of PEEK$() >So, >Dim T AS String >T = Peek$( pMem, 100000 ) will lead to have the same data 3x in memory by >now. >the original, Peek$(), and T
The compiler alocates a memory block for "t" of 100000 bytes, and copies the data directly from the memory address into the storage. The means one original buffer, and one string "copy" only exist, not three. If you made an expression of the statement, then yes, one more temporary "copy" would needed during processing of the line of string expression. For example, T = PEEK$(pMem,100000) + CHR$(0) would create a temporary string to handle the 1st part (PEEK$()) and then another to build the concatenated string, then the temporary string would be deleted, leaving the original data and a copy in "t" in memory. Quote: >Sure, when going out of scope, 2 memories will be lost in this example. >I would like to use the original memory directly. >Suppose i have data > 200mb or sort of.. (will not happen)
Virtual memory should take care of that, since flat addressing makes it theoretically possible to address a single allocation of up to 2Gb. If you have enough disk space to support that much virtual memory, that is! Quote: >If Peek$() would return an internal management 'handle' i could use:
Use a pointer to the original instead. Quote: >a = Instr( Peek$( pMem + 4, 100000 ), MkL$( 3 ) ) ) >As i see it, the data is now 2x in memory, still not desired.
Since would be evaluated as an expression, there would be one temporary "copy" in memory for the duration of INSTR(), but the copy would be freed when evaluation of INSTR is completed. Quote: >(I wonder, if Peek$() has a valid strptr, gonna check this one)
It cannot have a STRPTR, but it could be though of as having a VARPTR that the address specified. 8-) Lance PowerBASIC Support ------------------------------------------------------------------------- PowerBASIC, Inc. | 800-780-7707 Sales | "We put the Power in Basic!" 316 Mid Valley Center | 831-659-8000 Voice | http://www.powerbasic.com
|
Fri, 05 Sep 2003 20:57:12 GMT |
|
|
Peter Mander #9 / 17
|
Need to access resources without copying the data.
Quote:
> The following is JUST an example for discussion of instr() > #define MYLIST_MAXNAMES 4 > MYLIST RCDATA > { > MYLIST_MAXNAMES // Ammount of Records. > , 1L, "String1\0" > , 2L, "String2\0" > , 3L, "String3\0" > , 4L, "String4\0" > } > Suppose i would like to use: > a = Instr( pMem + 4, MkL$( 3 ), LenOfResoure& ) > These string functions are not possible unf.
Edwin, why don't you subtract the addresses of the strings to get their length, put it in ecx and use scasb to scan memory? I would think that inline assembly is the only approach that will get you what you want. You only need to add an extra string at the end to be able to calculate the length of the last string in the list. Peter. -- Peter Manders. "WARNING: Do not look into laser with remaining eye" Please remove the 'u' to reply.
|
Fri, 05 Sep 2003 19:51:23 GMT |
|
|
N #10 / 17
|
Need to access resources without copying the data.
I have no idea what scasb is, if you have an example? I already know the memory startaddress and length, so if an assembly routine could help me out here.. (it's a simple resource using RCDATA) LockResource returns the mem addres, SizeofResource() returns the length. Thanks a lot.
|
Sat, 06 Sep 2003 05:18:26 GMT |
|
|
N #11 / 17
|
Need to access resources without copying the data.
Thanks Lance, that made it more clear what Peek$()/PB actually does.
|
Sat, 06 Sep 2003 05:19:15 GMT |
|
|
Peter Mander #12 / 17
|
Need to access resources without copying the data.
Quote:
> I have no idea what scasb is, if you have an example? > I already know the memory startaddress and length, so if an assembly routine > could help me out here.. > (it's a simple resource using RCDATA) > LockResource returns the mem addres, SizeofResource() returns the length. > Thanks a lot.
Try this: '------------------------------------------------------------------------------- 'Instring function test using PowerBasic's inline assembler. ' 'by Peter Manders '------------------------------------------------------------------------------- #DIM ALL #REGISTER NONE '------------------------------------------------------------------------------- 'returns byte position in BufAdr, or -1 if not found. FUNCTION AsmInstr(BufAdr AS LONG, BufLen AS LONG, Search AS STRING) AS LONG LOCAL pSearch AS BYTE PTR LOCAL pBuffer AS BYTE PTR LOCAL SearchLeft AS LONG LOCAL SearchLen AS LONG pBuffer = BufAdr pSearch = STRPTR(Search) SearchLen = LEN(Search) SearchLeft = BufLen - SearchLen + 2 IF (SearchLen > 0) AND (SearchLeft >= 0) THEN NewScan: ! mov edi, pBuffer ! mov esi, pSearch ! mov ecx, SearchLeft ! mov al, [esi] ! repne scasb 'find byte in al ! OR ecx, ecx ! jz NotFound ! mov SearchLeft, ecx ! mov pBuffer, edi ! dec edi ! mov ecx, SearchLen ! repe cmpsb ! jnz NewScan FUNCTION = pBuffer - BufAdr - 1 EXIT FUNCTION NotFound: END IF FUNCTION = -1 END FUNCTION '------------------------------------------------------------------------------- FUNCTION PBMAIN LOCAL teststr AS STRING LOCAL search AS STRING teststr = "1234567890 abcdefghijklmnopqrstuvwxyz" search = "456" PRINT search; ":"; AsmInstr(STRPTR(teststr), LEN(teststr), search) search = "4" PRINT search; ":"; AsmInstr(STRPTR(teststr), LEN(teststr), search) search = "54" PRINT search; ":"; AsmInstr(STRPTR(teststr), LEN(teststr), search) search = "wxy" PRINT search; ":"; AsmInstr(STRPTR(teststr), LEN(teststr), search) search = "xyz" PRINT search; ":"; AsmInstr(STRPTR(teststr), LEN(teststr), search) search = "12345" PRINT search; ":"; AsmInstr(STRPTR(teststr), LEN(teststr), search) WAITKEY$ END FUNCTION -- Peter Manders. "WARNING: Do not look into laser with remaining eye" Please remove the 'u' to reply.
|
Sat, 06 Sep 2003 06:33:49 GMT |
|
|
N #13 / 17
|
Need to access resources without copying the data.
He, that's great, finally an asm equivalent! I have a small request though.. Can this scan adapted to be case insensitive? Since i use resources, i can't convert them to uppercase first (i don't want it either) Maybe ASM has this build in, i don't know anything about ASM. If not, i'm already helped much! Thanks,
|
Sun, 07 Sep 2003 00:52:44 GMT |
|
|
Peter Mander #14 / 17
|
Need to access resources without copying the data.
Quote:
> He, that's great, finally an asm equivalent! > I have a small request though.. > Can this scan adapted to be case insensitive? > Since i use resources, i can't convert them to uppercase first (i don't want > it either) > Maybe ASM has this build in, i don't know anything about ASM. > If not, i'm already helped much! > Thanks,
I usually don't do requests, but here you go: '------------------------------------------------------------------------------- 'Instring function test using PowerBasic's inline assembler. 'Case insensitive version added 2001-03-20 'by Peter Manders '------------------------------------------------------------------------------- #DIM ALL #REGISTER NONE '------------------------------------------------------------------------------- 'returns byte position in BufAdr, or -1 if not found. 'Case insensitive version. FUNCTION UAsmInstr(BufAdr AS LONG, BufLen AS LONG, Search AS STRING) AS LONG LOCAL pSearch AS BYTE PTR LOCAL pBuffer AS BYTE PTR LOCAL SearchLeft AS LONG LOCAL SearchLen AS LONG LOCAL LSearch AS STRING LSearch = LCASE$(Search) pBuffer = BufAdr pSearch = STRPTR(LSearch) SearchLen = LEN(LSearch) SearchLeft = BufLen - SearchLen + 2 IF (SearchLen > 0) AND (SearchLeft >= 0) THEN NewScan: ! mov esi, pBuffer ! mov edi, pSearch ! mov ecx, SearchLeft ScanLoop: ! lodsb ! cmp al, "A" ! jb CaseDone ! cmp al, "Z" ! ja CaseDone ! OR al, &H20 CaseDone: ! cmp al, [edi] ! je FindRest ! dec ecx ! jz NotFound ! jmp ScanLoop FindRest: ! mov SearchLeft, ecx ! mov pBuffer, esi ! mov ecx, SearchLen CmpLoop: ! dec ecx ! jz Foundit ! lodsb ! cmp al, "A" ! jb CaseDone2 ! cmp al, "Z" ! ja CaseDone2 ! OR al, &H20 CaseDone2: ! inc edi ! cmp al, [edi] ! je CmpLoop ! jmp NewScan Foundit: FUNCTION = pBuffer - BufAdr - 1 EXIT FUNCTION NotFound: END IF FUNCTION = -1 END FUNCTION '------------------------------------------------------------------------------- 'returns byte position in BufAdr, or -1 if not found. FUNCTION AsmInstr(BufAdr AS LONG, BufLen AS LONG, Search AS STRING) AS LONG LOCAL pSearch AS BYTE PTR LOCAL pBuffer AS BYTE PTR LOCAL SearchLeft AS LONG LOCAL SearchLen AS LONG pBuffer = BufAdr pSearch = STRPTR(Search) SearchLen = LEN(Search) SearchLeft = BufLen - SearchLen + 2 IF (SearchLen > 0) AND (SearchLeft >= 0) THEN NewScan: ! mov edi, pBuffer ! mov esi, pSearch ! mov ecx, SearchLeft ! mov al, [esi] ! repne scasb 'find byte in al ! OR ecx, ecx ! jz NotFound ! mov SearchLeft, ecx ! mov pBuffer, edi ! dec edi ! mov ecx, SearchLen ! repe cmpsb ! jnz NewScan FUNCTION = pBuffer - BufAdr - 1 EXIT FUNCTION NotFound: END IF FUNCTION = -1 END FUNCTION '------------------------------------------------------------------------------- FUNCTION PBMAIN LOCAL teststr AS STRING LOCAL search AS STRING teststr = "1234567890 AbCdEfGhijklmnopqrstuvwxyz" PRINT "Teststring: "; teststr PRINT search = "abc" PRINT "Sense Case: "; search; ":"; AsmInstr(STRPTR(teststr), LEN(teststr), search) search = "AbC" PRINT "Sense Case: "; search; ":"; AsmInstr(STRPTR(teststr), LEN(teststr), search) search = "abc" PRINT "No Case: "; search; ":"; UAsmInstr(STRPTR(teststr), LEN(teststr), search) search = "ABC" PRINT "No Case: "; search; ":"; UAsmInstr(STRPTR(teststr), LEN(teststr), search) WAITKEY$ END FUNCTION That'll be $50.00 :-) -- Peter Manders. "WARNING: Do not look into laser with remaining eye" Please remove the 'u' to reply.
|
Sun, 07 Sep 2003 04:35:30 GMT |
|
|
N #15 / 17
|
Need to access resources without copying the data.
You are a genius! I'll try this soon! Thanks, Quote:
>> He, that's great, finally an asm equivalent! >> I have a small request though.. >> Can this scan adapted to be case insensitive? >> Since i use resources, i can't convert them to uppercase first (i don't want >> it either) >> Maybe ASM has this build in, i don't know anything about ASM. >> If not, i'm already helped much! >> Thanks, >I usually don't do requests, but here you go: >'-------------------------------------------------------------------------- ----- >'Instring function test using PowerBasic's inline assembler. >'Case insensitive version added 2001-03-20 >'by Peter Manders >'-------------------------------------------------------------------------- ----- >#DIM ALL >#REGISTER NONE >'-------------------------------------------------------------------------- ----- >'returns byte position in BufAdr, or -1 if not found. >'Case insensitive version. >FUNCTION UAsmInstr(BufAdr AS LONG, BufLen AS LONG, Search AS STRING) AS >LONG >LOCAL pSearch AS BYTE PTR >LOCAL pBuffer AS BYTE PTR >LOCAL SearchLeft AS LONG >LOCAL SearchLen AS LONG >LOCAL LSearch AS STRING > LSearch = LCASE$(Search) > pBuffer = BufAdr > pSearch = STRPTR(LSearch) > SearchLen = LEN(LSearch) > SearchLeft = BufLen - SearchLen + 2 > IF (SearchLen > 0) AND (SearchLeft >= 0) THEN > NewScan: > ! mov esi, pBuffer > ! mov edi, pSearch > ! mov ecx, SearchLeft > ScanLoop: > ! lodsb > ! cmp al, "A" > ! jb CaseDone > ! cmp al, "Z" > ! ja CaseDone > ! OR al, &H20 > CaseDone: > ! cmp al, [edi] > ! je FindRest > ! dec ecx > ! jz NotFound > ! jmp ScanLoop > FindRest: > ! mov SearchLeft, ecx > ! mov pBuffer, esi > ! mov ecx, SearchLen > CmpLoop: > ! dec ecx > ! jz Foundit > ! lodsb > ! cmp al, "A" > ! jb CaseDone2 > ! cmp al, "Z" > ! ja CaseDone2 > ! OR al, &H20 > CaseDone2: > ! inc edi > ! cmp al, [edi] > ! je CmpLoop > ! jmp NewScan > Foundit: > FUNCTION = pBuffer - BufAdr - 1 > EXIT FUNCTION > NotFound: > END IF > FUNCTION = -1 >END FUNCTION >'-------------------------------------------------------------------------- ----- >'returns byte position in BufAdr, or -1 if not found. >FUNCTION AsmInstr(BufAdr AS LONG, BufLen AS LONG, Search AS STRING) AS >LONG >LOCAL pSearch AS BYTE PTR >LOCAL pBuffer AS BYTE PTR >LOCAL SearchLeft AS LONG >LOCAL SearchLen AS LONG > pBuffer = BufAdr > pSearch = STRPTR(Search) > SearchLen = LEN(Search) > SearchLeft = BufLen - SearchLen + 2 > IF (SearchLen > 0) AND (SearchLeft >= 0) THEN > NewScan: > ! mov edi, pBuffer > ! mov esi, pSearch > ! mov ecx, SearchLeft > ! mov al, [esi] > ! repne scasb 'find byte in al > ! OR ecx, ecx > ! jz NotFound > ! mov SearchLeft, ecx > ! mov pBuffer, edi > ! dec edi > ! mov ecx, SearchLen > ! repe cmpsb > ! jnz NewScan > FUNCTION = pBuffer - BufAdr - 1 > EXIT FUNCTION > NotFound: > END IF > FUNCTION = -1 >END FUNCTION >'-------------------------------------------------------------------------- ----- >FUNCTION PBMAIN >LOCAL teststr AS STRING >LOCAL search AS STRING > teststr = "1234567890 AbCdEfGhijklmnopqrstuvwxyz" > PRINT "Teststring: "; teststr > PRINT > search = "abc" > PRINT "Sense Case: "; search; ":"; AsmInstr(STRPTR(teststr), >LEN(teststr), search) > search = "AbC" > PRINT "Sense Case: "; search; ":"; AsmInstr(STRPTR(teststr), >LEN(teststr), search) > search = "abc" > PRINT "No Case: "; search; ":"; UAsmInstr(STRPTR(teststr), >LEN(teststr), search) > search = "ABC" > PRINT "No Case: "; search; ":"; UAsmInstr(STRPTR(teststr), >LEN(teststr), search) > WAITKEY$ >END FUNCTION >That'll be $50.00 :-) >-- >Peter Manders. >"WARNING: Do not look into laser with remaining eye" >Please remove the 'u' to reply.
|
Sun, 07 Sep 2003 18:11:06 GMT |
|
|
Page 1 of 2
|
[ 17 post ] |
|
Go to page:
[1]
[2] |
|