Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Another way?

Reply  
Thread Tools
mt2002's Avatar
Computer Specs
Senior Member with 926 posts.
 
Join Date: Sep 2005
Location: 127.0.0.1
Experience: Advanced
28-Nov-2008, 11:58 PM #1
Another way?
Hey everyone,

I have the following code (Modified to reduce size) :

Code:
//! statically create commands
static cmd_debug	_debugcmd;
static cmd_title	_titlecmd;
static cmd_timeout	_timeoutcmd;

//! add commands
internal_cmds[0] = (internal_cmd*)&_debugcmd;
internal_cmds[1] = (internal_cmd*)&_titlecmd;
internal_cmds[2] = (internal_cmd*)&_timeoutcmd;
All of the cmd_* classes derive from a pure virtual base class, internal_cmd. By storing all commands into an array of abstract pointers, I can work with any command using the same base class interface.

The problem that I dont like is the repetitiveness of this code. I have to statically create an object for each command and manually add them to the array, one at a time. Yuck.

Im looking for a better method that will let me dynamically add commands to the array...without using dynamic memory allocation of any kind nor STL as neither are implemented in this code running environment. I cant think of a way without needing dynamic memory though...

I *can* use a pointer to some location in memory to mimic dynamic memory though, but I am looking for a cleaner method as doing this may be dangerous as I would not know what is there in memory.

Does anyone have any better alternative methods that I can try?

Thanks!

*btw, What happened to the delete thread post button?
__________________
char c[3]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:59 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.