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: 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
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 Louie Landale, on Friday, March 11, 2005 5:05 PM

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
 13-Jan-2005 10:49
User is offline View Users Profile Print this message


Charlie Burrows

Posts: 9
Joined: 22-Sep-2004

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
Report this to a Moderator Report this to a Moderator
 13-Jan-2005 11:47
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 13-Jan-2005 12:35
User is offline View Users Profile Print this message


Charlie Burrows

Posts: 9
Joined: 22-Sep-2004

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
Report this to a Moderator Report this to a Moderator
 13-Jan-2005 12:51
User is offline View Users Profile Print this message


Antonio Norkus

Posts: 109
Joined: 28-Jun-2003

What is the contents of the buffer that causes it to crash? Seems to work fine on buffers I've passed into it.
Report this to a Moderator Report this to a Moderator
 13-Jan-2005 13:04
User is offline View Users Profile Print this message


Charlie Burrows

Posts: 9
Joined: 22-Sep-2004

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.
Report this to a Moderator Report this to a Moderator
 13-Jan-2005 13:33
User is offline View Users Profile Print this message


Charlie Burrows

Posts: 9
Joined: 22-Sep-2004

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?
Report this to a Moderator Report this to a Moderator
 13-Jan-2005 14:45
User is offline View Users Profile Print this message


Antonio Norkus

Posts: 109
Joined: 28-Jun-2003

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.

Report this to a Moderator Report this to a Moderator
 13-Jan-2005 14:50
User is offline View Users Profile Print this message


Charlie Burrows

Posts: 9
Joined: 22-Sep-2004

Thanks, i think that func is clean but there are leaks elsewhere possibly leaks into the string table.
Report this to a Moderator Report this to a Moderator
 19-Jan-2005 23:02
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

Are you saying that:
string s = stringOf(Buff)
causes memory leak, but
string s = tempStringOf(Buff)
does not?

Golly.

- Louie
Report this to a Moderator Report this to a Moderator
 24-Jan-2005 08:46
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 24-Jan-2005 19:45
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

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+
Report this to a Moderator Report this to a Moderator
 24-Jan-2005 19:59
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

Answer 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
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 0 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 0 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.