Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > BOOK: Professional C#, 2nd and 3rd Editions
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 18th, 2005, 06:10 AM
Registered User
 
Join Date: Apr 2005
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!
 
Old April 21st, 2005, 08:12 AM
Registered User
 
Join Date: Apr 2005
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?





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.