Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
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
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Paul Worrall, on Wednesday, November 15, 2006 9:12 AM

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.
 13-Nov-2006 14:56
User is offline View Users Profile Print this message


Michiel van der Wulp

Posts: 6
Joined: 18-Mar-2005

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
Report this to a Moderator Report this to a Moderator
 14-Nov-2006 12:16
User is offline View Users Profile Print this message


Paul Worrall

Posts: 87
Joined: 30-Sep-2003

Answer 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.
Report this to a Moderator Report this to a Moderator
 15-Nov-2006 22:30
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

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.
Report this to a Moderator Report this to a Moderator
 20-Dec-2007 10:53
User is offline View Users Profile Print this message


Eric Piallat

Posts: 13
Joined: 10-Dec-2007

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
Report this to a Moderator Report this to a Moderator
 20-Dec-2007 14:18
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

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
Report this to a Moderator Report this to a Moderator
 20-Dec-2007 19:54
User is offline View Users Profile Print this message


Douglas Zawacki

Posts: 58
Joined: 17-Oct-2006

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.
Report this to a Moderator Report this to a Moderator
 20-Dec-2007 20:25
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

That's a bit alarming. Must be careful when using Buffers, don't adjust the 'length' and also use tempStringOf.
Report this to a Moderator Report this to a Moderator
 20-Dec-2007 20:56
User is offline View Users Profile Print this message


Douglas Zawacki

Posts: 58
Joined: 17-Oct-2006

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.
Report this to a Moderator Report this to a Moderator
 20-Dec-2007 23:07
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

'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.
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 10:10
User is offline View Users Profile Print this message


Eric Piallat

Posts: 13
Joined: 10-Dec-2007

I didn't think about setting to the null char!

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:
length (buffer set)
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"
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 15:26
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

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
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 17:20
User is offline View Users Profile Print this message


Eric Piallat

Posts: 33
Joined: 26-Jan-2004

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
Report this to a Moderator Report this to a Moderator
 7-Jan-2008 20:40
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

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. Sounds like a challenge especially if that space has not actually been used before.

- Louie
Report this to a Moderator Report this to a Moderator
 12-Feb-2008 21:43
User is offline View Users Profile Print this message


Bruce Tuskey

Posts: 77
Joined: 2-Mar-2004

"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
Report this to a Moderator Report this to a Moderator
 12-Feb-2008 22:22
User is offline View Users Profile Print this message


Pete Kowalski

Posts: 301
Joined: 7-Feb-2003

@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
Report this to a Moderator Report this to a Moderator
 12-Feb-2008 23:52
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

The attached shows that deleting the buffer also sets it to null

- Louie
Report this to a Moderator Report this to a Moderator
 13-Feb-2008 12:41
User is offline View Users Profile Print this message


Scott Boisvert

Posts: 348
Joined: 14-Apr-2006

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
Report this to a Moderator Report this to a Moderator
 13-Feb-2008 13:00
User is offline View Users Profile Print this message


Pekka Mäkinen

Posts: 276
Joined: 18-Mar-2004

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/
Report this to a Moderator Report this to a Moderator
 22-Feb-2008 21:38
User is offline View Users Profile Print this message


Bruce Tuskey

Posts: 77
Joined: 2-Mar-2004

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)
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.