Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > BOOK: Professional C#, 2nd and 3rd Editions
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional C#, 2nd and 3rd Editions
This is the forum to discuss the Wrox book Professional C#, 3rd Edition by Simon Robinson, Christian Nagel, Karli Watson, Jay Glynn, Morgan Skinner, Bill Evjen; ISBN: 9780764557590
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C#, 2nd and 3rd Editions 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 April 18th, 2005, 06:10 AM
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Obnox
Default Take the address of a stack based array

Consider the following code:
Code:
public unsafe class PointerArray
    {
        private int size;
        private long* pArray;

        public PointerArray(int size)
        {
            this.size = size;
            long* pArray = stackalloc long [size];
            this.pArray = &(pArray);
        }
    }
I want to assign the address of the stack based array to the pointer, using
Code:
this.pArray = &(pArray);
During compile I get the following error message:
Quote:
quote:Cannot implicitly convert type long** to long*
What am I doing wrong? Is there another way of keeping a stack based array within the scope of a class

Thnx!
  #2 (permalink)  
Old April 21st, 2005, 08:12 AM
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Obnox
Default

I solved the problem myself however not completely satisfied. Here's wy: I've changed the code to:
Code:
    public unsafe class PointerArray
    {
        private int size;
        public long* pArray;

        public PointerArray(int size)
        {
            this.size = size;
        }
    }
Now, I use the pArray as a field, rather than a property. Obviously I have to make it public, which is the exact fact that i do not like this solution. However it does work, the only thing I need to do after instantiating the class is assign a pointer reference to the property like this:
Code:
int size = 10
long* pArray = stackalloc long [size];
PointerArray pa = new PointerArray(size);
pa.pArray = pArray;
Note also that I do not assign the address anymore but simply assign the reference.

I'm a bit mixed up on this topick. Can anyone help with a proper solution?
 


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
array address problem chris1012 Java Basics 3 December 18th, 2007 11:46 AM
conditional xslt processing based on java array twilson997 XSLT 7 June 28th, 2006 07:32 AM
traversing a tree based on an array of strings muki XSLT 1 February 16th, 2006 09:54 AM
how to pass address of an array to a dll(in c++) iceman1188 General .NET 0 May 30th, 2004 09:19 PM
Key based array in VBScript? rgalehouse Classic ASP Basics 3 March 1st, 2004 06:05 PM



All times are GMT -4. The time now is 03:42 PM.


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