Discussion:
MSVC 1.5 - how do I force strings into _CODE segment?
(too old to reply)
Ed
2006-11-29 06:00:04 UTC
Permalink
Raw Message
I'm not sure if this is the best group to post this, but I have a
question about ancient MSVC 1.5.

Right now, all strings in my code, i.e. text in quotes, are put in the
_DATA segment by default.

I need to tell the compiler/linker to put these in the _CODE segment
where there is more space available.

Is there a way to do this? I've looked through the MSVC 1.5 help files
and can't find any compiler or linker switches that do this.

Thanks for your help!

Ed
William DePalo [MVP VC++]
2006-11-29 06:27:35 UTC
Permalink
Raw Message
Post by Ed
I'm not sure if this is the best group to post this, but I have a
question about ancient MSVC 1.5.
:-)
Post by Ed
Right now, all strings in my code, i.e. text in quotes, are put in the
_DATA segment by default.
I need to tell the compiler/linker to put these in the _CODE segment
where there is more space available.
Is there a way to do this? I've looked through the MSVC 1.5 help files
and can't find any compiler or linker switches that do this.
If there is any way to move all the strings in one go then I don't know
about it. But this example (which I stole from the help) shows how to do it
a string at a time:

char __based( __segname( "_CODE" ) ) mystring[] =
"Code-based string.\n";

Regards,
Will
Ed
2006-11-29 08:28:01 UTC
Permalink
Raw Message
Thanks Will for the suggestion. I have been using this approach, but
it's a tedious way to move strings to CODE segment, because I have
thousands of them. I've seen vague references that there might be a
compiler or linker switch to do this, but haven't found it yet.

Hopefully, somone will have some insight on that.

Ed
Post by William DePalo [MVP VC++]
Post by Ed
I'm not sure if this is the best group to post this, but I have a
question about ancient MSVC 1.5.
:-)
Post by Ed
Right now, all strings in my code, i.e. text in quotes, are put in the
_DATA segment by default.
I need to tell the compiler/linker to put these in the _CODE segment
where there is more space available.
Is there a way to do this? I've looked through the MSVC 1.5 help files
and can't find any compiler or linker switches that do this.
If there is any way to move all the strings in one go then I don't know
about it. But this example (which I stole from the help) shows how to do it
char __based( __segname( "_CODE" ) ) mystring[] =
"Code-based string.\n";
Regards,
Will
David Lowndes
2006-11-29 08:32:17 UTC
Permalink
Raw Message
Post by Ed
Right now, all strings in my code, i.e. text in quotes, are put in the
_DATA segment by default.
I need to tell the compiler/linker to put these in the _CODE segment
where there is more space available.
Is there a way to do this? I've looked through the MSVC 1.5 help files
and can't find any compiler or linker switches that do this.
Ed,

Is there a compiler setting to "eliminate duplicate strings" - or
something like that?

Dave
Ed
2006-11-29 08:59:00 UTC
Permalink
Raw Message
Dave,

Thanks for your outstanding suggetion. I found a switch /Gf that
consolidates duplicate strings. That saved me over half of my string
space or 28K. That's a huge savings and just saved me many hours of
work, moving strings one at a time.

THANK YOU!
Ed
Post by David Lowndes
Post by Ed
Right now, all strings in my code, i.e. text in quotes, are put in the
_DATA segment by default.
I need to tell the compiler/linker to put these in the _CODE segment
where there is more space available.
Is there a way to do this? I've looked through the MSVC 1.5 help files
and can't find any compiler or linker switches that do this.
Ed,
Is there a compiler setting to "eliminate duplicate strings" - or
something like that?
Dave
David Lowndes
2006-11-29 09:32:06 UTC
Permalink
Raw Message
Post by Ed
Thanks for your outstanding suggetion. I found a switch /Gf that
consolidates duplicate strings. That saved me over half of my string
space or 28K. That's a huge savings and just saved me many hours of
work, moving strings one at a time.
I'm glad that's helped.

Has it also moved the strings to the code segment?

Dave
Ed
2006-11-30 15:59:52 UTC
Permalink
Raw Message
Dave,

That's a good question. There is a not an easy way to tell if it moved
all the strings to the code segment. My guess is that this just
consolidated the duplicate strings, but all the unique strings may
still be in the data segment.

The /Gf switch help information did not mention anything about moving
strings into a different segment. It only mentioned consolidation of
duplicates.

Ed
Post by David Lowndes
Post by Ed
Thanks for your outstanding suggetion. I found a switch /Gf that
consolidates duplicate strings. That saved me over half of my string
space or 28K. That's a huge savings and just saved me many hours of
work, moving strings one at a time.
I'm glad that's helped.
Has it also moved the strings to the code segment?
Dave
Lawrence Groves
2006-12-06 14:51:14 UTC
Permalink
Raw Message
Post by Ed
Dave,
That's a good question. There is a not an easy way to tell if it moved
all the strings to the code segment. My guess is that this just
consolidated the duplicate strings, but all the unique strings may
still be in the data segment.
The /Gf switch help information did not mention anything about moving
strings into a different segment. It only mentioned consolidation of
duplicates.
I think the reason the David asked his question just needs a bit of thinking
about. I'm sure you'll find he's right if you check, and all the strings (or
at least all the consolidated ones) have been moved to the code segment.

What would happen if the consolidated strings were left where they were in
the data segment? It would be quite easy for one part of the program to
change it's copy of the string and then cause every other part of the
program that uses the same string to go wrong.... *because they are shared*.
The code segment is read-only, I believe, so that can't happen if they've
been moved.

Loz.
sigmund southpaw
2011-04-18 19:46:10 UTC
Permalink
Raw Message
Hello,

I have a solution; but it doesn't move your strings to the _CODE segment...

I have written several LARGE model apps using VC 1.5 and have learned that VC 1.5 places all text strings (that aren't explicitly declared) implicitly into a section of memory called the Default Data Segment (here after referred to as the DDS). Even in the LARGE model the DDS is only 65k in size. Data is assigned from the lowest address up, and the stack is initialized to the top of the DDS and can thus grow downward.

You can use the Compiler switch "/Gx-" to force all Data to be FAR Data (including text strings), thus moving them out of the DDS. I have written programs with close to 65k of text strings imbedded. If the stack grows down too far during program execution it can lead to some "interesting" debugging experiences...

Hope this helps,
'Sig
Post by Ed
I'm not sure if this is the best group to post this, but I have a
question about ancient MSVC 1.5.
Right now, all strings in my code, i.e. text in quotes, are put in the
_DATA segment by default.
I need to tell the compiler/linker to put these in the _CODE segment
where there is more space available.
Is there a way to do this? I've looked through the MSVC 1.5 help files
and can't find any compiler or linker switches that do this.
Thanks for your help!
Ed
Post by William DePalo [MVP VC++]
If there is any way to move all the strings in one go then I don't know
about it. But this example (which I stole from the help) shows how to do it
char __based( __segname( "_CODE" ) ) mystring[] =
"Code-based string.\n";
Regards,
Will
Post by Ed
Thanks Will for the suggestion. I have been using this approach, but
it's a tedious way to move strings to CODE segment, because I have
thousands of them. I've seen vague references that there might be a
compiler or linker switch to do this, but haven't found it yet.
Hopefully, somone will have some insight on that.
Ed
Post by David Lowndes
Ed,
Is there a compiler setting to "eliminate duplicate strings" - or
something like that?
Dave
Post by Ed
Dave,
Thanks for your outstanding suggetion. I found a switch /Gf that
consolidates duplicate strings. That saved me over half of my string
space or 28K. That's a huge savings and just saved me many hours of
work, moving strings one at a time.
THANK YOU!
Ed
I am glad that is helped.
Has it also moved the strings to the code segment?
Dave
Post by Ed
Dave,
That's a good question. There is a not an easy way to tell if it moved
all the strings to the code segment. My guess is that this just
consolidated the duplicate strings, but all the unique strings may
still be in the data segment.
The /Gf switch help information did not mention anything about moving
strings into a different segment. It only mentioned consolidation of
duplicates.
Ed
Post by Lawrence Groves
I think the reason the David asked his question just needs a bit of thinking
about. I'm sure you'll find he's right if you check, and all the strings (or
at least all the consolidated ones) have been moved to the code segment.
What would happen if the consolidated strings were left where they were in
the data segment? It would be quite easy for one part of the program to
change it's copy of the string and then cause every other part of the
program that uses the same string to go wrong.... *because they are shared*.
The code segment is read-only, I believe, so that can't happen if they've
been moved.
Loz.
sigmund southpaw
2011-04-18 20:00:51 UTC
Permalink
Raw Message
Hello,

I have a solution; but it doesn't move your strings to the _CODE segment...

I have written several LARGE model apps using VC 1.5 and have learned that VC 1.5 places all text strings (that aren't explicitly declared) implicitly into a section of memory called the Default Data Segment (here after referred to as the DDS). Even in the LARGE model the DDS is only 65k in size. Data is assigned from the lowest address up, and the stack is initialized to the top of the DDS and can thus grow downward.

You can use the Compiler switch "/Gx-" to force all Data to be FAR Data (including text strings), thus moving them out of the DDS. I have written programs with close to 65k of text strings imbedded. If the stack grows down too far during program execution it can lead to some "interesting" debugging experiences...

Hope this helps,
'Sig
Post by Ed
I'm not sure if this is the best group to post this, but I have a
question about ancient MSVC 1.5.
Right now, all strings in my code, i.e. text in quotes, are put in the
_DATA segment by default.
I need to tell the compiler/linker to put these in the _CODE segment
where there is more space available.
Is there a way to do this? I've looked through the MSVC 1.5 help files
and can't find any compiler or linker switches that do this.
Thanks for your help!
Ed
Post by William DePalo [MVP VC++]
If there is any way to move all the strings in one go then I don't know
about it. But this example (which I stole from the help) shows how to do it
char __based( __segname( "_CODE" ) ) mystring[] =
"Code-based string.\n";
Regards,
Will
Post by Ed
Thanks Will for the suggestion. I have been using this approach, but
it's a tedious way to move strings to CODE segment, because I have
thousands of them. I've seen vague references that there might be a
compiler or linker switch to do this, but haven't found it yet.
Hopefully, somone will have some insight on that.
Ed
Post by David Lowndes
Ed,
Is there a compiler setting to "eliminate duplicate strings" - or
something like that?
Dave
Post by Ed
Dave,
Thanks for your outstanding suggetion. I found a switch /Gf that
consolidates duplicate strings. That saved me over half of my string
space or 28K. That's a huge savings and just saved me many hours of
work, moving strings one at a time.
THANK YOU!
Ed
I am glad that is helped.
Has it also moved the strings to the code segment?
Dave
Post by Ed
Dave,
That's a good question. There is a not an easy way to tell if it moved
all the strings to the code segment. My guess is that this just
consolidated the duplicate strings, but all the unique strings may
still be in the data segment.
The /Gf switch help information did not mention anything about moving
strings into a different segment. It only mentioned consolidation of
duplicates.
Ed
Post by Lawrence Groves
I think the reason the David asked his question just needs a bit of thinking
about. I'm sure you'll find he's right if you check, and all the strings (or
at least all the consolidated ones) have been moved to the code segment.
What would happen if the consolidated strings were left where they were in
the data segment? It would be quite easy for one part of the program to
change it's copy of the string and then cause every other part of the
program that uses the same string to go wrong.... *because they are shared*.
The code segment is read-only, I believe, so that can't happen if they've
been moved.
Loz.
Post by sigmund southpaw
Hello,
I have a solution; but it doesn't move your strings to the _CODE segment...
I have written several LARGE model apps using VC 1.5 and have learned that VC 1.5 places all text strings (that aren't explicitly declared) implicitly into a section of memory called the Default Data Segment (here after referred to as the DDS). Even in the LARGE model the DDS is only 65k in size. Data is assigned from the lowest address up, and the stack is initialized to the top of the DDS and can thus grow downward.
You can use the Compiler switch "/Gx-" to force all Data to be FAR Data (including text strings), thus moving them out of the DDS. I have written programs with close to 65k of text strings imbedded. If the stack grows down too far during program execution it can lead to some "interesting" debugging experiences...
Hope this helps,
'Sig
Loading...