![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: What does "tempStringOf" do? Topic Summary: The tempStringOf function is used for showing the diff result... Created On: 13-Nov-2006 14:56 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() Answer: Every new string declared or constructed during the execution a script is entered into a "string table". The memory occupied by this table is not released until the DOORS session is terminated. Using Buffers to manipulate text data avoids allocating string table memory since the memory used for a Buffer is released when you delete it, however it is still sometimes necessary to convert a Buffer into a string e.g. for assigning the value to an attribute, and this is where tempStringOf is used. tempStringOf returns a string representation of a Buffer without using string table memory, however the string so created should not be relied upon to exist beyond the statement in which it is used. | |
![]() |
|
The dxl help files use the function tempStringOf once, to show the result of a diff function, in the chapter about history.
I want to do exactly that, so the function works for me, but I wonder why/if it differs from stringOf?
Regards,
Michiel
|
|
![]() |
|
![]() |
|
Every new string declared or constructed during the execution a script is entered into a "string table". The memory occupied by this table is not released until the DOORS session is terminated. Using Buffers to manipulate text data avoids allocating string table memory since the memory used for a Buffer is released when you delete it, however it is still sometimes necessary to convert a Buffer into a string e.g. for assigning the value to an attribute, and this is where tempStringOf is used. tempStringOf returns a string representation of a Buffer without using string table memory, however the string so created should not be relied upon to exist beyond the statement in which it is used.
|
|
![]() |
|
![]() |
|
The attached code illustrates the problem with tempStringOf. Changing the buffer b after the assignment also changes the value of s. Thus s becomes an alias for b; but that gets sticky if you delete(b).
You can use tempStringOf only when the string value is going to be promptly deposited outside of some variable, such as assigning to an attribute, printing, displaying on a dialog, or sending to a file. |
|
![]() |
|
![]() |
|
Just discovered another reason why you can't rely on tempStringOf: you can't use it after a "length" perm!
In fact, it seems to give you a "char * pointer" (hello, C users!) to the data inside the buffer, without actually copying anything. So it's not a "convert to string" but actually a "cast to string". Try this: Buffer b = create b = "abcdefg" print stringOf b print "\n" print tempStringOf b print "\n" length (b,1) print stringOf b print "\n" print tempStringOf b print "\n" As tempStringOf does not take the buffer's length into account it displays: abcdefg abcdefg a abcdefg |
|
![]() |
|
![]() |
|
Never use tempStringOf when assigning the key of a Skip List.
put(aSkipList, tempStringOf(Buffer b), anykindofvariable) // never do this ------------------------- David Pechacek AAI Services Textron dpechacek@sc-aaicorp.com David.Pechacek@gmail.com |
|
![]() |
|
![]() |
|
stringOf(Buffer) creates an entry into the string table and makes a copy of the contents of the buffer.
tempStringOf(Buffer) actually returns the pointer to the referenced buffer. Therefore, if you change the contents of the buffer then the resultant tempStringOf() will reflect the change. Understanding the way tempStringOf() works allows you to detemine when it's use is appropriate. I personally use it on very rare occasions because of the side effects previously noted. |
|
![]() |
|
![]() |
|
That's a bit alarming. Must be careful when using Buffers, don't adjust the 'length' and also use tempStringOf.
|
|
![]() |
|
![]() |
|
ok, I'm a bit confused.
Eric, you are using a length perm that I don't see in my dxl documentation. In fact, I believe that length(b,1) that you are using actually truncates the buffer to the length you provided. Therefore, it seems that all the coding you have is working as expected. Is there documentation on this length perm that I am missing? I'm still on 8.1. |
|
![]() |
|
![]() |
|
'length' is in the Buffer section, one that gets the length and this one that sets the length. Setting the length:
length(buf, 23) has been, until now, a reliable way to truncate a buffer; the alternative being something like this: buf = stringOf(buf[0:22]) which wastes string-table space. You can also truncate a buffer by inserting a null character. That doesn't work perfectly well either, as per attached. |
|
![]() |
|
![]() |
|
![]() Of course this way it works fine, I think from now I will only use this: void setLength (Buffer b, int len) { set (b, len, null char) length (b, len) } Thank you, Louie ! ![]() Btw, from DXL Reference Help of DOORS 7.1, don't know if it changed with DOORS 8: Declaration void length(Buffer b, int len) Operation Sets the length of a buffer. This is normally used for truncating buffers, but can also be used to lengthen them. The DXL program is responsible for the content of the buffer. Example Buffer buf = create buf = "abcd" length(buf,2) print "<" (stringOf buf) ">" // prints "ab" |
|
![]() |
|
![]() |
|
Eric the
set (b, len, null char) length (b, len) is redundant. You just need the length(b, len) line. The first line is essentially nullified by the second. ------------------------- David Pechacek AAI Services Textron dpechacek@sc-aaicorp.com David.Pechacek@gmail.com |
|
![]() |
|
![]() |
|
David,
In fact not if you look carefully at Louie's example. The "set" perm allows the "tempStringOf" perm working properly, but not the "StringOf" nor the "::..(Buffer, string)" perms. The "length" perm is sufficient for stringOf and string concatenation, but not for tempStringOf (see my first example). Thus, both are needed if you want to use tempStringOf for logs and debugs, *and* still have a Buffer compatible with Buffer manipulation perms. What would be sufficient for both stringOf and tempStringOf would be the "b=stringOf b[0:len]" perm, but it creates an unnecessary string in the string table. ------------------------- E. Piallat CeBeNetwork |
|
![]() |
|
![]() |
|
I would add a check to your setLength() function such that it does nothing if the desired length is longer than or equal to the current length.
If you REALLY want to extend the length of the buffer into the unknown then I'd suspect you'd need to look for the existing trailing NULL character and deal with it; setting it to something that's neither NULL nor anything else. ![]() - Louie |
|
![]() |
|
![]() |
|
"tempStringOf" is also great for use in comparison statements.
if(tempStringOf(bufTest) == "It Works"){ } Remember when deleting buffers to set the variable to null: delete(bufTest) bufTest = null ------------------------- Bruce Tuskey Sr. Principle Engineer Tuskey@gmail.com "All that is gold does not glitter, not all those who wander are lost:..." - Gandalf the Grey (JRR Tolkien) Edited: 12-Feb-2008 at 21:45 by Bruce Tuskey |
|
![]() |
|
![]() |
|
@Bruce:
Why do you recommend clearing a buffer by setting it to null? I would feel deleting a buffer is good enough. ------------------------- pete.kowalski(at)motorola.com |
|
![]() |
|
![]() |
|
The attached shows that deleting the buffer also sets it to null
- Louie |
|
![]() |
|
![]() |
|
I believe the setempty (Buffer b) also sets the buffer to null.
------------------------- Scott Boisvert Engineering Tools Administrator L-3 Communications - Avionics Systems scott.boisvert@l-3com.com |
|
![]() |
|
![]() |
|
No. As the name says it just empties a buffer, but the space is still reserved and the buffer variable points to that space.
------------------------- Pekka.Makinen@softqa.fi SoftQA Oy -http://www.softqa.fi/ |
|
![]() |
|
![]() |
|
I do it out of habit now. In earlier versions of DOORS deleting some memory structures did not always set them to null. It would only free up the memory, but the initial pointer would still be present and therefore would not show up as "null." Skip Lists were the biggest problem. I haven't checked lately to see if this is still the case.
------------------------- Bruce Tuskey Sr. Principle Engineer Tuskey@gmail.com "All that is gold does not glitter, not all those who wander are lost:..." - Gandalf the Grey (JRR Tolkien) |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
What does "tempStringOf" do?
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.