Posted: Tue Jul 25, 2006 6:46 pm
Inc,
Again, Traumatics routine is not at risk sofar unless you count in that it is declarering 4 times the size of the memory needed!
A normal string is 1 byte per character. And Unicode is 2 bytes per char. So converting from string to unicode is TWICE the length of string PLUS the zero byte(s) at the end of the UNICODE string.
See ? "Len(string)*2 * #SIZEOF_WORD" so length of string TIMES 2 and then times size of a word but since WORD is 2 bytes there is a 4 times longer than needed string. This was all that is needed "Len(string) * #SIZEOF_WORD + 2" and the 2 bytes are for the zero to denotes the end of the UNICODE string.
Oke sofar things are clear. But in your latest version you make *out protected (local) which is fine, than allocate memory ON the heap (fine). But at the end of the proc L() the return is the adress of the memory area ON the heap. By using that it is distroyed leaving that region of memory still on the HEAP! But nobody (i think even PB itself) is NOT nowing where it is it leaves unused memory. Do this more than once and you have a problem, you run out of memory and your program grows and grows in memory size. Unless you end your program than PB (as I understand) frees the memory!! Not before. In desiging a program that is 'always' on (like a media center) you get a memory problem in the long run.
So your code is valid as Traumatics and my code is (more) valid. Both are right, but the usage is the difference. Yours (in the example) is short run, only 1 film and exit. Mine is for 24h on (and longer) and noumerous films tv programs DVD perhaps. See it will build up.
Hope this is clear. And thanks for looking in the IEnumfilter issue.
Jan V.
Again, Traumatics routine is not at risk sofar unless you count in that it is declarering 4 times the size of the memory needed!
A normal string is 1 byte per character. And Unicode is 2 bytes per char. So converting from string to unicode is TWICE the length of string PLUS the zero byte(s) at the end of the UNICODE string.
Code: Select all
Procedure.l L(string.s)
*out = AllocateMemory(Len(string)*2 * #SIZEOF_WORD)
MultiByteToWideChar_(#CP_ACP, 0, string, -1, *out, Len(string))
ProcedureReturn *out
EndProcedure
Oke sofar things are clear. But in your latest version you make *out protected (local) which is fine, than allocate memory ON the heap (fine). But at the end of the proc L() the return is the adress of the memory area ON the heap. By using that it is distroyed leaving that region of memory still on the HEAP! But nobody (i think even PB itself) is NOT nowing where it is it leaves unused memory. Do this more than once and you have a problem, you run out of memory and your program grows and grows in memory size. Unless you end your program than PB (as I understand) frees the memory!! Not before. In desiging a program that is 'always' on (like a media center) you get a memory problem in the long run.
So your code is valid as Traumatics and my code is (more) valid. Both are right, but the usage is the difference. Yours (in the example) is short run, only 1 film and exit. Mine is for 24h on (and longer) and noumerous films tv programs DVD perhaps. See it will build up.
Hope this is clear. And thanks for looking in the IEnumfilter issue.
Jan V.