![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Does buffer b = b2[x:y] add to the string table? Topic Summary: Created On: 13-Jan-2005 10:49 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() Answer: Off Topic: I've got a function similar to this. Under that is a function that replaces all occurances of a specific character in a buffer with a string substitution. That function using the 'contains(Buffer)' function that looks for the next occurrance of the character. Turns out that's a LOT more speedy, and IIRC less memory useage than manually examining each character in turn. So your code could look like this: ReplaceChar(&Buff, FromChar, ToString) { Use 'contains' to replace all 'FromChar' to 'ToString' in the Buffer While its found, [1] move the before part to the buffer [2] insert the ToString. When done insert the rest of the Buffer } ReplaceNPChararcters(&Buff) { ReplaceChar('\n' ...) ReplaceChar('\r' ...) ReplaceChar('\f' ...) ReplaceChar('\t' ... } - Louie | |
![]() |
|
I'm trying to generate as little garbage as possible. I'm told by reliable sources that the example adds a string to the string table.
// Imagine the buffer init doesn't come from a string! Buffer b1 = "This is a test" String s = b1[0:5] But if you do this: // Imagine the buffer init doesn't come from a string! Buffer b1 = "This is a test" Buffer b2 = b1[0:5] is there an intermediate string? Assuming the answer is "No" is DXL smart enough to know the types of function arguments it requres and apply this knowledge to the above example e.g. void example(Buffer eg) { // Do something ... } // Imagine the buffer init doesn't come from a string! Buffer b1 = "This is a test" example(b1[0:5]) Just trying to plug the memory leaks. Cheers Charlie. Edited: 13-Jan-2005 at 12:20 by Charlie Burrows |
|
![]() |
|
![]() |
|
According to the manual, buf[x:y] returns a Buffer or a string depending on the type assigned.
If assigned to a buffer I don't know if a string is added to the string table, but I suspect not. Take a look at Jeremy's Technical tip - Memory management in DXL, in particular the undocumented function string tempStringOf(Buffer) which does not add to the string table. http://www.telelogic.com/resources/get_file.cfm?id=3518 ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
|
![]() |
|
Thanks for the quick answer. Maybe I should give the reason for my question. My DXL program keeps crashing and I have been advised that it's likely to have run out of memory. I have started using buffers instead of strings and taking various steps including the use of tempStringOf but it still always crashes in the same place. The function is goes wrong in is a simple character replacement function. Any input on how to handle this better would be welcome.
Ignore the debug_... functions they just write stuff to a log file.
Edited: 13-Jan-2005 at 12:36 by Charlie Burrows |
|
![]() |
|
![]() |
|
What is the contents of the buffer that causes it to crash? Seems to work fine on buffers I've passed into it.
|
|
![]() |
|
![]() |
|
I doesn't crash straight away. It can run my app for a while and eventually it'll crash but it almost always crashes in this function. Maybe try passing it a random buffer in a loop, something I haven't tried. Also FYI it generally gets some way through the message before it crashes i.e. it crashes in the middle of the function not at the ends.
|
|
![]() |
|
![]() |
|
Ok I tried that and it worked just fine for many many iterations and didn't crash at all.
Will the fact that I'm setting result to null mean that delete will operate on a null pointer? |
|
![]() |
|
![]() |
|
Definitely delete the buffer before setting the pointer to null.
I tried the attached on a module with some OLEs (notoriously big strings) and didn't see any memory leakage. Setting to null before deleting leaked a lot of memory. |
|
![]() |
|
![]() |
|
Thanks, i think that func is clean but there are leaks elsewhere possibly leaks into the string table.
|
|
![]() |
|
![]() |
|
Are you saying that:
string s = stringOf(Buff) causes memory leak, but string s = tempStringOf(Buff) does not? Golly. - Louie |
|
![]() |
|
![]() |
|
From Jeremy's tech tip: "The string created by tempStringOf(buffer) is very temporary and should not be assumed to exist beyond the statement in which it is used".
I think this means that you can use it for assigning to an attribute, but not for assigning to a variable that will be read later in the script. See Jeremy's Tech Tip: http://www.telelogic.com/resources/get_file.cfm?id=3518 ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
|
![]() |
|
Looks like you can use tempStringOf for Buffers as well?
obj.NameAttr = tempStringOf(InBuffer) print tempStringOf(InBuffer) Buffer ReturnBuff = tempStringOf(InBuffer). If that's true, then I'm wasting time with Buffers since I've got lots of library functions that return strings but use Buffers intermediately, but convert back to string at the end. - Louie+ |
|
![]() |
|
![]() |
|
Off Topic:
I've got a function similar to this. Under that is a function that replaces all occurances of a specific character in a buffer with a string substitution. That function using the 'contains(Buffer)' function that looks for the next occurrance of the character. Turns out that's a LOT more speedy, and IIRC less memory useage than manually examining each character in turn. So your code could look like this: ReplaceChar(&Buff, FromChar, ToString) { Use 'contains' to replace all 'FromChar' to 'ToString' in the Buffer While its found, [1] move the before part to the buffer [2] insert the ToString. When done insert the rest of the Buffer } ReplaceNPChararcters(&Buff) { ReplaceChar('\n' ...) ReplaceChar('\r' ...) ReplaceChar('\f' ...) ReplaceChar('\t' ... } - Louie |
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.