473,734 Members | 2,511 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 #1
89 3838
For those that missed the other threads here is the explanation why I want
something like this:

For 32 bit compilers:

int (32 bit signed integer) is fast, it's translated to single 32 bit cpu
instructions.

long long (64 bit signed integer) is slow, it's translated to multiple 32
bit cpu instructions.

For 64 bit compilers

long long (64 bit signed integer) should be fast, it's translated to a
single 64 bit cpu instruction.

I want to write code just once ! not three times ! and I want maximum speed
!

So I need a generic integer class which will use the appriorate class, the
program must decide what's necessary at runtime, and still give good
performance !

I believe/hope the provided example after some minor fixes should be able to
do what I want ;) !

Bye,
Skybuck.

Aug 29 '07 #2
Well, since the code doesn't compile yet I can't look at the asm generated
but now that I think about it...

Maybe C++ does like polymorhpic or virtual function stuff for compileable
code and that might introduce more overhead than it's worth.

Remains to be seen.

Bye,
Skybuck.
Aug 29 '07 #3
On Aug 29, 7:02 am, "Skybuck Flying" <s...@hotmail.c omwrote:
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)
This argument is wrong in two ways. It assumes things that are not
true and then draws conclusions that don't follow.

Delphi implements objects, and virtual methods. Any language that has
these features is able to operate on values where the type is not
known at compile time.
On the other hand neither this nor what you included below will do
what you started off trying to suggest. They are just methods by
which different instructions can be used at a point in the logic flow
depending on the sort of variable under consideration.

Aug 29 '07 #4
Yeah and possibly:

TdoubleGenericI nteger = int128; // implemented manually.

These doubles could be used to detected generic integer overflows, range
check errors and other kinds of problems.

Bye,
Skybuck.
Aug 29 '07 #5

"MooseFET" <ke******@rahul .netwrote in message
news:11******** **************@ q5g2000prf.goog legroups.com...
On Aug 29, 7:02 am, "Skybuck Flying" <s...@hotmail.c omwrote:
>Hello,

This morning I had an idea how to write Scalable Software in general.
Unfortunatel y 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)

This argument is wrong in two ways. It assumes things that are not
true and then draws conclusions that don't follow.

Delphi implements objects, and virtual methods. Any language that has
these features is able to operate on values where the type is not
known at compile time.
Without the mentioned features writing scalable software, including writing
scalable math routines becomes impractical.

Even with virtual methods it would become slow.
On the other hand neither this nor what you included below will do
what you started off trying to suggest. They are just methods by
which different instructions can be used at a point in the logic flow
depending on the sort of variable under consideration.
It does exactly what I want it to do, it does it slowly, so it's not what I
want it to do.

Bye,
Skybuck.
Aug 29 '07 #6
Somebody else also had an interesting idea:

It comes down to this:

1. Generate multiple libraries, for example:

32 bit version
true 64 bit version
emulated 64 bit version

2. It might have some problems:

Problem 1: parameters for routine are different.
Problem 2: calling for routines are different because of parameters.
Problem 3: debugging problem, different libraries same source <- can't be,
source was slightly modified for each generate library.

These problems could make finding a solution more complex.

It does solve another problem:

Different parts of the application can have different versions.

This idea is definetly worth exploring.

Bye,
Skybuck.
Aug 29 '07 #7
Problem 4:

Distribution size grows considerable.

3 Different libraries must be supplied.

Only one library has to be loaded.

Maybe two if different parts required it.

Biggest problem:

The debugging problem.

That's what I don't like about it.

Debugging very important for me.

How can different libraries be debugged with the same code ? Where only one
declartion is different, it was modified during the build ?

Strange.

Bye,
Skybuck.

Aug 29 '07 #8
On 2007-08-29 16:02, Skybuck Flying wrote:
Hello,
Why the crossposting to all those different groups, especially when this
subject is off-topic in most of them (what does sci.electronics .design
have to do with anything). Please read the the FAQ before posting any
more messages, http://www.parashift.com/c++-faq-lite/ start by reading
section 5. I've replied only to comp.lang.c++.
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)
It's not a very good scheme, using virtual functions is not very
performance efficient and you'd be using them all over the place. If
it's not know at compile-time what size is needed then a library for
arbitrary precision is probably better than this solution.
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;
You are wrong to assume that an int is always 32 bits.
>
public:

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

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

void Display();
Instead of a Display() function, overload the << operator.
};

class TSkybuckInt64 : TSkybuckGeneric Integer
{
private:
long long mInteger;
Same goes for long, it's not guaranteed to be 64 bits.
>
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[])
Non-standard main
{
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 A32(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;
Those variables are all out of scope.

I'm not very impressed with the idea so far, I think you can make
something much more useful with templates, that should also give a lot
more efficiency than you can get with virtual functions.

--
Erik Wikström
Aug 29 '07 #9
mpm
On Aug 29, 10:39?am, MooseFET <kensm...@rahul .netwrote:
On Aug 29, 7:02 am, "Skybuck Flying" <s...@hotmail.c omwrote:
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)

This argument is wrong in two ways. It assumes things that are not
true and then draws conclusions that don't follow.

Delphi implements objects, and virtual methods. Any language that has
these features is able to operate on values where the type is not
known at compile time.

On the other hand neither this nor what you included below will do
what you started off trying to suggest. They are just methods by
which different instructions can be used at a point in the logic flow
depending on the sort of variable under consideration.
IMO, this Skybuck poster is whacked. Mentally so.

I'll wager that if you just parse his code and remove all occurances
of the letters "skybuck" you'll discover its someone else's work and
he's just inserted his jibberish to make himself feel more
important. Probably right out of a help file or compiler manual or
something.

I can practically guarantee you he did not write any of this code.
-which of course would explain why it doesn't even do what he claims
it's supposed to do.

And I've never me the guy (girl?, it?, whatever Skybuck is).

Aug 29 '07 #10

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

Similar topics

1
2930
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
17233
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
4789
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
1254
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
2698
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
8946
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
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
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...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
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
6735
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.