473,761 Members | 7,710 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 3850
MooseFET wrote:
On Aug 30, 6:02 am, Ron Natalie <r...@spamcop.n etwrote:
>MooseFET wrote:
>>This statement is incorrect. C, C++, Borland Pascal and it
decendants, and just about every other language I can think of allow
you to declare a new type to be the same as a simple type, allow
conditional compiles, and allow include files. You don't need to have
two copies of the source code.
Incorrect. C and C++ certainly do not.

You claim the above and then go on to say the below:
> You can #define or typedef
something that appears to be a type but they aren't distinct types.

The "typedef" declares a new type.
No it does not. It makes an alias for an existing type. You can't
distinguish between the typedef and the original type either through
overloading or typeid or anything else.

Aug 31 '07 #81
On Aug 31, 3:13 pm, Ron Natalie <r...@spamcop.n etwrote:
MooseFET wrote:
On Aug 30, 6:02 am, Ron Natalie <r...@spamcop.n etwrote:
MooseFET wrote:
>This statement is incorrect. C, C++, Borland Pascal and it
decendants, and just about every other language I can think of allow
you to declare a new type to be the same as a simple type, allow
conditional compiles, and allow include files. You don't need to have
two copies of the source code.
Incorrect. C and C++ certainly do not.
You claim the above and then go on to say the below:
You can #define or typedef
something that appears to be a type but they aren't distinct types.
The "typedef" declares a new type.

No it does not.
Yes it does in all the ways tha matter to the argument with Skybuck.
It causes a new name to be associated with a type. This makes it a
declaration of a type. Just because C doesn't do as strict of type
checking as some other languages doesn't make it not a declare of a
type. After the typedef has been done there is a new symbol that is a
type.

Aug 31 '07 #82

"David Brown" <da***@westcont rol.removethisb it.comskrev i en meddelelse
news:46******** **************@ news.wineasy.se ...

If you learn to use Usenet properly before trying to post this stuff, it
would be a lot easier to get you back on the path of sane software
development. It's not worth spending time answering you if you can't
write questions or comments that make sense.
It's this particular troll's mode of operation. News2020 was more fun.
>

Sep 1 '07 #83

"Frederick Williams" <"Frederick Williams"@antis pamhotmail.co.u k.invalid>
skrev i en meddelelse
news:46******** *******@antispa mhotmail.co.uk. invalid...
Skybuck Flying wrote:
>>
Hello,

This morning I had an idea ...

I hope that this doesn't sound impolite, but why are you posting to
sci.electronics .design and alt.math?
....because he knows that there are always a few people in
'sci.electronic s.design' that will take the bait!
Sep 1 '07 #84
MooseFET wrote:
:: On Aug 31, 3:13 pm, Ron Natalie <r...@spamcop.n etwrote:
::: MooseFET wrote:
:::: On Aug 30, 6:02 am, Ron Natalie <r...@spamcop.n etwrote:
::::: MooseFET wrote:
:::
:::::: This statement is incorrect. C, C++, Borland Pascal and it
:::::: decendants, and just about every other language I can think of
:::::: allow you to declare a new type to be the same as a simple
:::::: type, allow conditional compiles, and allow include files.
:::::: You don't need to have two copies of the source code.
::::: Incorrect. C and C++ certainly do not.
:::
:::: You claim the above and then go on to say the below:
:::
::::: You can #define or typedef
::::: something that appears to be a type but they aren't distinct
::::: types.
:::
:::: The "typedef" declares a new type.
:::
::: No it does not.
::
:: Yes it does in all the ways tha matter to the argument with
:: Skybuck. It causes a new name to be associated with a type. This
:: makes it a declaration of a type. Just because C doesn't do as
:: strict of type checking as some other languages doesn't make it
:: not a declare of a type. After the typedef has been done there is
:: a new symbol that is a type.

We don't care much about how Skybuck defines a "new type".

After the typedef there is a new symbol that is the name of the type.
The type, however, is exactly the same as it was before the typedef.
It has just got a "nickname", or an alias.
typedef Skybuck Bucky;

doesn't create a new person!

Bo Persson
Sep 1 '07 #85
Skybuck Flying sp**@hotmail.co m posted to sci.electronics .design:
>
"David Brown" <da***@westcont rol.removethisb it.comwrote in message
news:46******** **************@ news.wineasy.se ...
>Skybuck Flying wrote:
>>"David Brown" <da***@westcont rol.removethisb it.comwrote in
message news:46******** *************** @news.wineasy.s e...
Skybuck Flying wrote:
There is definetly a speed difference especially for mul and div
for the modes I described.
>
Why do I have to choose the data type ?
>
Why can't the program choose the data type at runtime ?
>
If *you* are writing the program, *you* should know what sort of
data is
stored in each variable. *You* can then tell the compiler by
choosing
an appropriate data type. Is that so hard to grasp? It is up to
*you* to figure out that what limits there will be on the size of
the data you are using, and therefore pick 32-bit or 64-bit (or
whatever) integers
for your program. If you think there could be large variations
in the sizes, then either use a data type that will certainly be
big enough, or pick one with no arbitrary limit (there are
multiple precision integer libraries available for most
languages) , or use a dynamically typed language.

Well that clearly sucks.

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.

So if your program needs 32 bits, use 32 bits. If it needs 64
bits, use 64 bits.

Yes very simply statement.

Achieving this in a scalable way is what this thread is all about.

Re-writing code, or writing double code, or even using multiple
libraries is not really what this is about.

It's nearly impossible to achieve without hurting performance. Only
solutions might be c++ templates or generics, not even sure how easy
it would be to switch between two generated class at runtime.

Bye,
Skybuck.
Can't speak for other libraries but the integer and floating point
routines GCC C++ libraries are written as templates. Just don't
expect to change the CPU ALU mode on the fly. (at least not on
x86_64, PPC, MIPS or SPARC architectures.)

Sep 1 '07 #86
Skybuck Flying sp**@hotmail.co m posted to sci.electronics .design:
>
"Stephen Sprunk" <st*****@sprunk .orgwrote in message
news:46******** *************** @free.teranews. com...
>"Skybuck Flying" <sp**@hotmail.c omwrote in message
news:fb******* ***@news5.zwoll 1.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.
Precisely why we use typing and let the compiler do it. It moves the
overhead of the detection clear out of the running program.
Sep 1 '07 #87
You have valid points.

Just because an if statement/switch to 32 bit code proved faster on my
system and the simple test program doesn't have to mean it will always be
faster, or always be faster on other chips.

I am pretty much done investigating this issue.

I am now convinced extending the code with int64's is ok.

And I will do it only at those places where it's absolutely necessary, the
rest will remain 32 bits.

So current code base is being converted/upgrade to a mix of 32 bit and 64
bit numbers.

Haven't look at the compare statements for 64 bits and copy statements,
there some more overhead.

Some new algorithm parts to cope with 64 bits as well, so program will
probably be a bit slower anyway.

It's the price to pay lol ;)

Bye,
Skybuck.

Sep 1 '07 #88
Good get lost.

Bye,
Skybuck.

"Frank Birbacher" <bl************ @gmx.netwrote in message
news:5j******** ***@mid.dfncis. de...
Skybuck Flying schrieb:
>Give me wings bitch ! =D

Time to ban you.

Frank

Sep 1 '07 #89
ChairmanOfTheBo red wrote:
Gee... Look! The SkyTard is back, and he even answered his own post
seven times!
What are you on? He wouldn't be the SkyTard otherwise!
Sep 2 '07 #90

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
17266
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
1257
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
2702
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
9531
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
10115
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
9905
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
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7332
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
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
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
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
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.