473,769 Members | 4,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing Scalabe Software in C++

Hello,

This morning I had an idea how to write Scalable Software in general.
Unfortunately with Delphi 2007 it can't be done because it does not support
operating overloading for classes, or record inheritance (records do have
operator overloading)

The idea is to write a generic integer class with derived integer classess
for 8 bit, 16 bit, 32 bit, 64 bit and 64 bit emulated.

Then at runtime the computer program can determine which derived integer
class is needed to perform the necessary calculations.

The necessary integer class is instantiated and assigned to a generic
integer class variable/reference and the generic references/variables are
used to write the actual code that performs the calculations.

Below is a demonstration program, it's not yet completely compiling, but
it's getting close.

// TestWritingScal ableSoftware.cp p : Defines the entry point for the console
application.
//
#include "stdafx.h"

class TSkybuckGeneric Integer
{
};
class TSkybuckInt32 : public TSkybuckGeneric Integer
{
private:
int mInteger;

public:

// constructor with initializer parameter
TSkybuckInt32( int ParaValue );

// add operator overloader
TSkybuckInt32& operator+( const TSkybuckInt32& ParaSkybuckInt3 2 );

void Display();
};

class TSkybuckInt64 : TSkybuckGeneric Integer
{
private:
long long mInteger;

public:
// constructor with initializer parameter
TSkybuckInt64( long long ParaValue );

// add operator overloader
TSkybuckInt64& operator+( const TSkybuckInt64& ParaSkybuckInt6 4 );

void Display();
};

//
// TSkybuckInt32

// constructor
TSkybuckInt32:: TSkybuckInt32( int ParaValue )
{
mInteger = ParaValue;
}

// add operator overloader
TSkybuckInt32& TSkybuckInt32:: operator+ ( const TSkybuckInt32&
ParaSkybuckInt3 2 )
{
mInteger = mInteger + ParaSkybuckInt3 2.mInteger;
return *this;
}

void TSkybuckInt32:: Display()
{
printf( "%d \n", mInteger );
}

//
// TSkybuckInt64
//
// constructor
TSkybuckInt64:: TSkybuckInt64( long long ParaValue )
{
mInteger = ParaValue;
}

// add operator overloader
TSkybuckInt64& TSkybuckInt64:: operator+ ( const TSkybuckInt64&
ParaSkybuckInt6 4 )
{
mInteger = mInteger + ParaSkybuckInt6 4.mInteger;
return *this;
}

void TSkybuckInt64:: Display()
{
printf( "%lu \n", mInteger );
}

int _tmain(int argc, _TCHAR* argv[])
{
long long FileSize;
long long MaxFileSize32bi t;

// must write code like this to use constructor ? can't just declare
a,b,c ?
TSkybuckInt32 A32 = TSkybuckInt32( 30 );
TSkybuckInt32 B32 = TSkybuckInt32( 70 );
TSkybuckInt32 C32 = TSkybuckInt32( 0 );
C32 = A32 + B32;
C32.Display();

TSkybuckInt64 A64 = TSkybuckInt64( 30 );
TSkybuckInt64 B64 = TSkybuckInt64( 70 );
TSkybuckInt64 C64 = TSkybuckInt64( 0 );
C64 = A64 + B64;
C64.Display();

FileSize = 1024; // kilobyte
FileSize = FileSize * 1024; // megabyte
FileSize = FileSize * 1024; // gigabyte
FileSize = FileSize * 1024; // terrabyte

MaxFileSize32bi t = 1024; // kilobyte
MaxFileSize32bi t = MaxFileSize32bi t * 1024; // megabyte
MaxFileSize32bi t = MaxFileSize32bi t * 1024; // gigabyte
MaxFileSize32bi t = MaxFileSize32bi t * 4; // 4 gigabyte
if (FileSize < MaxFileSize32bi t)
{
TSkybuckGeneric Integer AGeneric = TSkybuckInt32( 30 );
TSkybuckGeneric Integer BGeneric = TSkybuckInt32( 70 );
TSkybuckGeneric Integer CGeneric = TSkybuckInt32( 0 );
} else
{
TSkybuckGeneric Integer AGeneric = TSkybuckInt64( 30 );
TSkybuckGeneric Integer BGeneric = TSkybuckInt64( 70 );
TSkybuckGeneric Integer CGeneric = TSkybuckInt64( 0 );
}

CGeneric = AGeneric + BGeneric;
CGeneric.Displa y();

while (1)
{
}

return 0;
}

Probably minor compile issue's remain:

Error 1 error C2243: 'type cast' : conversion from 'TSkybuckInt64 *__w64 '
to 'const TSkybuckGeneric Integer &' exists, but is inaccessible
y:\cpp\tests\te st writing scalable software generic math\version
0.01\testwritin gscalablesoftwa re\testwritings calablesoftware \testwritingsca lablesoftware.c pp
152

Error 2 error C2243: 'type cast' : conversion from 'TSkybuckInt64 *__w64 '
to 'const TSkybuckGeneric Integer &' exists, but is inaccessible
y:\cpp\tests\te st writing scalable software generic math\version
0.01\testwritin gscalablesoftwa re\testwritings calablesoftware \testwritingsca lablesoftware.c pp
153

Error 3 error C2243: 'type cast' : conversion from 'TSkybuckInt64 *__w64 '
to 'const TSkybuckGeneric Integer &' exists, but is inaccessible
y:\cpp\tests\te st writing scalable software generic math\version
0.01\testwritin gscalablesoftwa re\testwritings calablesoftware \testwritingsca lablesoftware.c pp
154

Error 4 error C2065: 'CGeneric' : undeclared identifier y:\cpp\tests\te st
writing scalable software generic math\version
0.01\testwritin gscalablesoftwa re\testwritings calablesoftware \testwritingsca lablesoftware.c pp
157

Error 5 error C2065: 'AGeneric' : undeclared identifier y:\cpp\tests\te st
writing scalable software generic math\version
0.01\testwritin gscalablesoftwa re\testwritings calablesoftware \testwritingsca lablesoftware.c pp
157

Error 6 error C2065: 'BGeneric' : undeclared identifier y:\cpp\tests\te st
writing scalable software generic math\version
0.01\testwritin gscalablesoftwa re\testwritings calablesoftware \testwritingsca lablesoftware.c pp
157

How to solve the remaining issue's ?

Bye,
Skybuck.
Aug 29 '07
89 3862
"Skybuck Flying" <sp**@hotmail.c omwrote in message
news:fb******** **@news2.zwoll1 .ov.home.nl...
Lot's of code will have to be 64 bit.

My guess is the performance impact will be noticeable ! ;)
Do some actual _measurements_ and find out, rather than guessing. Emulating
64-bit operations even when not required is almost always cheaper in both
programmer and CPU time than trying to detect and handle cases in which not
to use emulation.

"Rules of Optimization:
Rule 1: Don't do it.
Rule 2 (for experts only): Don't do it yet."
- M.A. Jackson

"More computing sins are committed in the name of efficiency (without
necessarily achieving it) than for any other single reason - including blind
stupidity."
- W.A. Wulf

"We should forget about small efficiencies, say about 97% of the time:
premature optimization is the root of all evil."
- Donald Knuth
S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from http://www.teranews.com

Aug 31 '07 #61
"Skybuck Flying" <sp**@hotmail.c omwrote in message
news:fb******** **@news5.zwoll1 .ov.home.nl...
Absolutely nonsense.

If I want I can write a computer program that runs 32 bit when possible
and 64 bit emulated when needed.
Yes, it's entirely possible to do that.
My computer program will outperform your "always 64 emulated" program WITH
EASE.
No, it won't. Post an actual test program using your method, and I'll
produce a program that does the same thing with my method, and we can
compare runtimes.
The only problem is that I have to write each code twice.

A 32 bit version and a 64 bit version.
No, you can write the code once and compile it twice.
I simply instantiate the necessary object and run it.
First of all, you must pay the cost of determining which type to use. Even
ignoring that, tracking down which code path to execute for that object at
runtime will be slower than simply using 64-bit operations (which may or may
not need to be emulated) all the time.
Absolutely no big deal.

The only undesirable property of this solution is two code bases.
Wrong. You only need one code base, but the poor performance of such a
solution will be a "big deal".
Your lack fo programming language knownledge and experience is definetly
showing.
Are you talking to yourself? _Every single person_ commenting on this
thread is telling you you're wrong.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from http://www.teranews.com

Aug 31 '07 #62
In comp.arch Stephen Sprunk <st*****@sprunk .orgwrote:
"Skybuck Flying" <sp**@hotmail.c omwrote in message
news:fb******** **@news5.zwoll1 .ov.home.nl...
>Absolutely nonsense.

If I want I can write a computer program that runs 32 bit when possible
and 64 bit emulated when needed.

Yes, it's entirely possible to do that.
>My computer program will outperform your "always 64 emulated" program WITH
EASE.

No, it won't. Post an actual test program using your method, and I'll
produce a program that does the same thing with my method, and we can
compare runtimes.
>The only problem is that I have to write each code twice.

A 32 bit version and a 64 bit version.

No, you can write the code once and compile it twice.
>I simply instantiate the necessary object and run it.

First of all, you must pay the cost of determining which type to use. Even
ignoring that, tracking down which code path to execute for that object at
runtime will be slower than simply using 64-bit operations (which may or may
not need to be emulated) all the time.
>Absolutely no big deal.

The only undesirable property of this solution is two code bases.

Wrong. You only need one code base, but the poor performance of such a
solution will be a "big deal".
>Your lack fo programming language knownledge and experience is definetly
showing.

Are you talking to yourself? _Every single person_ commenting on this
thread is telling you you're wrong.
And at least one person (me) put him in a kill file after reading the first
3 of his posts.
S
--
Aug 31 '07 #63

"Stephen Sprunk" <st*****@sprunk .orgwrote in message
news:46******** *************** @free.teranews. com...
"Skybuck Flying" <sp**@hotmail.c omwrote in message
news:fb******** **@news5.zwoll1 .ov.home.nl...
>The world is not completely 64 bit, The world is not statis it
fluctuates.

Sometimes the program only needs 32 bits, sometimes 64 bits.

Always choosing 64 bits would hurt performance LOL.

Not if you have a 64-bit machine; even if you're using a 32-bit machine,
emulating 64-bit operations s will hurts performance less than trying to
detect the appropriate choice and then act on that information.
For addition and subtraction probably.

For multiple and division some performance could be reduced for 32 bits but
would still be faster than simulating it.

Whatever the case maybe.

The point is the detection is the overhead if cpu can do the detection that
overhead might disappear ! ;) :)

Bye,
Skybuck.
Aug 31 '07 #64
Actually what I wrote only applies to doing the check each time.

If the check only has to be done once for large parts of code, there will
definetly be performance gains achievable ! ;)

(I already wrote that elsewhere but ok ;))

Bye,
Skybuck.
Aug 31 '07 #65
I don't agree with that.

Write large parts of code, do a check once.

Voila, only problem you will have two codes.

Bye,
Skybuck.
Aug 31 '07 #66
Now I see what those persons where bitching about.

It's called the instruction prefix which is part of the instruction
encoding.

Which if I interpret the manual correctly means this instruction prefix is
added before each instruction.

That means it's hard coded into the instruction and this means only one mode
can be selected.

So it's not an efficient way to switch modes during runtime, since the
instruction prefixes would need to be changed, which requires changes in
many memory locations.

Finally it might be interesting for compilers that won't to generate
multiple code paths, they might just need a few bit switches while
generating the instructions... but why bother... why not use some other
method to specify the operand size which might be more reliable.

From the manual:
"
The operand-size override prefix allows a program to switch between 16- and
32-bit operand
sizes. Either size can be the default; use of the prefix selects the
non-default size. Use of 66H
followed by 0FH is treated as a mandatory prefix by some SSE/SSE2/SSE3
instructions. Other
use of the 66H prefix with MMX/SSE/SSE2/SSE3 instructions is reserved; such
use may cause
unpredictable behavior.
The address-size override prefix (67H) allows programs to switch between 16-
and 32-bit
addressing. Either size can be the default; the prefix selects the
non-default size. Using this
prefix and/or other undefined opcodes when operands for the instruction do
not reside in
memory is reserved; such use may cause unpredictable behavior.
"

So far this was the 16/32 bit mode some people were bitching about ;)

Now I go look for a 64 bit mode switch.

Bye,
Skybuck.
Aug 31 '07 #67
However somebody else is still bitching about something else I think:

"
Intel introduced a bit
in the segment descriptor of the executable code, equivalent to your
BitMode variable, to specify whether the default code size is 16 bits
or 32 bits.
"

Where can I find more information about this ? (Me go search in manuals some
more ! ;))

Bye,
Skybuck.
Aug 31 '07 #68
Hi!

Skybuck Flying schrieb:
I wouldn't call that "Scalable Software" :)

It doesn't even scale properly at runtime.

Only one can be chosen at compile time.
So if you use the virtual function approach you can decide at runtime
which of the following you want to support:

- 16bit integer
- 32bit integer
- 32bit integer, emulated
- 64bit integer
- 64bit integer, emulated

combined with any of:

- i286 optimized
- i386 optimized
- i486 optimized
- i586 optimized
- i686 optimized
- 64bit integer instruction set

combined with any of:

- various flavours with different cache sizes

When you got all code paths in one single "über"-library I'll blame you:
it's too big for the 64kB RAM of my i286. On the other hand I'll blame
you if it won't run on:

- 128bit integer instruction set (yet to be invented)

And then we do the same for floating point numbers which come in 32bit,
64bit, 80bit, 128bit already on current CPU. Which can be mixed with or
without the use of ix87, MMX, MMXext, SSE 1 to 3, special addon cards
for math calculation (e.g. physics board for hardcore gamers).

And then I want to use your library on SPARC, PPC, ARM, Alpha, ...

My statements:

- yes, you can do a single check at the start of your program to choose
whether to use 32bit native, 64bit native, or 64bit emulated
- no, you do not have to code three times. you can use the compiler to
generate the code for you by the use of templates
- yes, the code would work without virtual functions
- no, I won't use your library because I only want to pay for what I
need. And I don't need this sort of code bloat.
- no, this approach can not scale to infinity without recompilation of
your library (e.g. using a compiler which can generate 128bit instructions)
- yes, you could use virtual functions and have "plugins" for the
various architecutres. the main library would detect the right "plugin",
load it, and use it
- yes, this would be essentially the same as providing distinct
libraries the first place
- yes, for theory it is nice to think about the polymorphic behaviour

Frank
Aug 31 '07 #69
No,

That newsgroup full with retards, that's all LOL.

Bye,
Skybuck.
Aug 31 '07 #70

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2932
by: Bill | last post by:
I'm writing a company intranet site, and on the home page, I'd like there to be links to some of the software that the employees frequently use on their own computer. This will be the inducement to get them to use the intranet home page as their default home page, and visit it frequently. For example a program which is under: "C:\Program Files\Now Software\Now Up-to-Date\NUD.exe" if I write that link into the hyperlink, it will not...
385
17305
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like extraneous jargons, such as in the Unix & Perl community. Unlike mathematicians, where in mathematics there are no fewer jargons but each and every one are
2
4793
by: RickH | last post by:
System.UnauthorizedAccessException Cannot write to the registry key. Is what I get trying to write a value in a HKCU\Software key. My InfoPath form is fully trusted. I have full permissions on the key according to Regedit permissions Using vb.net 2003 For that matter, a Windows form I created doesn't allow me to delete a key, and I can't write a key value in my Outlook com add-in, either. Account has admin priviledges. I guess I have...
0
1962
by: Chris Mullins | last post by:
I have an application that installs some 64-bit binaries for development use in Visual Studio 2005. As such I want them to appear in the .Net References menu when someone attempts to "Add References" to their project. Doing this means (normally) writing to the registry key: HKLM\Software\Microsoft\.NetFramework\v2.0.50727\AssemblyFoldersEx\MyNewBinaries, with a default string value of C:\Program Files\MyBinaries.
1
2057
by: Chris Mullins | last post by:
I need to write to the 32-bit registry, and need to do so from a 64-bit MSI. It never occurred to me that this would be difficult... I have an application that installs some 64-bit binaries for development use in Visual Studio 2005. As such I want them to appear in the .Net References menu when someone attempts to "Add References" to their project. Doing this means (normally) writing to the registry key: ...
6
1259
by: mcse jung | last post by:
Here is asample program that writes a program and then executes it. Do you knowof a much simpler way of writing a program that writes a program? """ ----------------------------------------------------------------------------- Name: _writePythonCode.py Purpose: This script writes Python code and thentransfers control to it. Author: MCSEJUNG
30
2705
by: Cramer | last post by:
I've finally gotton board with TDD (test driven development) and wow is it effective! I went from sceptic to True Believer with my first effort. My question: According to the various books and articles I have read about TDD, a good unit test does not rely on the database or other such external/environmental conditions. More generally, a good unit test is atomic and makes as few assumptions about its runtime environment as possible. But...
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.