There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express php pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Design question - C++


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
mt2002's Avatar
Computer Specs
Senior Member with 573 posts.
 
Join Date: Sep 2005
Location: 127.0.0.1
Experience: Advanced
05-Jul-2008, 04:55 PM #1
Design question - C++
Hey everyone

I have a design related question using C++. Im rewriting my paging code (again! I just cant seem to find a nice interface for it!), however there is one thing that has been a little bothering me.

I have two structures defined as follows. Please keep in mind these are hardware structures, so I cannot change the format of any of the structs.

Code:
//! page table entry
struct page_pte {

	//! page flags
	uint8_t		m_flags;

	//! physical frame address of page (Must be 4K aligned)
	uint8_t		m_addrLo;
	uint16_t	m_addrHi;
};

//! page directory entry
struct page_pde {

	//! page directory flags
	uint8_t		m_flags;

	//! base address of page table (Must be 4K aligned)
	uint8_t		m_addrLo;
	uint16_t	m_addrHi;
};
The only difference between these two structures are 3 bits. These 3 bits are reserved in page_pte but are used in page_pde. These bits are inside of the structs flags member.

Because of this, they have practically the same structure, format, everything--and are very interchangeable. The only thing that differs them is those 3 single bits within their flags member.

My question is: Should I combine them into a single data structure, or keep them separate? If I keep them separate, I will be having alot of duplicate routines working on both data structures as they are practically the same. If I combine them, I lose the aspect of object orientation.

What do you think I should do? I have been thinking about this for some time now, and cannot seem to be able to decide on what I should do here.

Thanks for any suggestions!
__________________

"Within C++, there is a much smaller and cleaner language struggling to get out." - Bjarne Stroustrup
Work: Tech Support, Programmer; A+ 220-602 Certified

Last edited by mt2002 : 05-Jul-2008 05:03 PM.
lotuseclat79's Avatar
Distinguished Member with 9,921 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
06-Jul-2008, 04:58 PM #2
Hi mt2002,

The so-called duplicate routines are not really working on the same data structure, but different instances of nearly identical data structures - not the same.

I would keep them separate, as the 3 reserved bits in the pte are serving a very specific purpose not shared by the pde.

If you were to combine them, the only differentiation would have to be that of the types of each structure, and you would still have to make that determination in the code. It is a trade-off, and the better trade-off is not to introduce confusion when separation of purpose fits the need.

-- Tom
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction between a mere artisan or specialist and a real seeker after truth. - Einstein wrote in 1944.

Some say knowledge is power, I say knowledge without action is powerless. - lotuseclat79

Don't confuse action with movement. - Hemingway to Gardner

Imagination is more important than knowledge. - Einstein
mt2002's Avatar
Computer Specs
Senior Member with 573 posts.
 
Join Date: Sep 2005
Location: 127.0.0.1
Experience: Advanced
06-Jul-2008, 10:47 PM #3
Thanks

I am going to keep them separate then for now and see how it goes I decided to just create two header files to separate them: pde.h and pdt.h.

Instead of creating routines to interface with them (As I was originally going to do) I decided to just keep the members public as only the physical frame manager will be working with it anyways.

If there are any further suggestions, please feel free to let me know!
__________________

"Within C++, there is a much smaller and cleaner language struggling to get out." - Bjarne Stroustrup
Work: Tech Support, Programmer; A+ 220-602 Certified
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

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 02:21 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.