Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2008 by Ivor Horton; ISBN: 9780470225905
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 22nd, 2012, 01:48 PM
Authorized User
Points: 57, Level: 1
Points: 57, Level: 1 Points: 57, Level: 1 Points: 57, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Didn't understand ch4:Arrays of pointers

Hi! I don't understand pages 181,182,183.

Especially the section that says:
"Compared to using a ‘normal’ array, the pointer array normally carries less overhead in terms of space. With an array, you would need to make each row the length of the longest string, and six rows of seventeen bytes each is 102 bytes, so by using a pointer array you have saved a whole -1 bytes!"

Why I have saved 1 byte?

Figure 4-7 shows that in the case of the pointer array I am using 103 bytes. I don't understand why 24 bytes are allocated for the pointer array?

In pg. 182 in 3rd paragraph it is mentioned that "With the pointer array as above you just need to swap the pointers". How do I do that?

Thanks
  #2 (permalink)  
Old February 10th, 2012, 08:12 PM
Authorized User
Points: 96, Level: 1
Points: 96, Level: 1 Points: 96, Level: 1 Points: 96, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 2 Times in 2 Posts
Default

It's -1 byte In the normal array if you set the length of the longest string Hopalong Cassidy\0 17 bytes then each string would be 17 times 6 which is 102 bytes. In the pointer array if you count all the bytes in the strings would be 79. Each pointer would require 4 bytes to hold the address of the string therefore 24 bytes are used by pointers bringing the total byte count to 103.

To swap the pointers just change the names of the pointers
char* pstr1 = "Robert Redford"
char* pstr2 = "Hopalong Cassidy"
change to
char* pstr2 = "Robert Redford"
char* pstr1 = "Hopalong Cassidy"
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with Ch4 Exercise 3! xiao_mao_mimi BOOK: Ivor Horton's Beginning Java, Java 7 Edition 1 December 22nd, 2011 02:37 PM
Ch4 Problem daivos03 JSP Basics 9 January 30th, 2006 01:57 AM
Pointers and Arrays C++ odie All Other Wrox Books 1 July 10th, 2003 01:45 PM



All times are GMT -4. The time now is 10:26 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.