473,473 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Questions about stackalloc and inline structure arrays.

Two questions here:

1. Is there any particular reason why when using stackalloc, the code byte
*buffer = stackalloc byte[50]; works, but code like byte *buffer; buffer =
stackalloc byte[50]; is considered incorrect syntax? Was this an oversight,
a stylistic design, or is there a technical reason it won't work?

2. I was reading an older(circa 2000) question[1] posted to one of these
groups in which Eric Gunnerson mentions that the C# team was still talking
about a way to declare inlined arrays of base types in structures,
basically:
struct myStruct
{
int[5] fiveArrays; //5 ints all in a row in memory, obviously would need
better syntax
}
out of my own curiosity, has anything about this come up recently? Is the
team still considering it? Is something perhaps coming up(or is there
something there in 1.1 I've not managed to find?).

1. http://tinyurl.com/vi0s
Nov 15 '05 #1
6 2813
Daniel,
2. I was reading an older(circa 2000) question[1] posted to one of these
groups in which Eric Gunnerson mentions that the C# team was still talking
about a way to declare inlined arrays of base types in structures,
basically:
struct myStruct
{
int[5] fiveArrays; //5 ints all in a row in memory, obviously would need
better syntax
}
out of my own curiosity, has anything about this come up recently? Is the
team still considering it? Is something perhaps coming up(or is there
something there in 1.1 I've not managed to find?).

It's planned for v2.0 (Whidbey), with the syntax

struct myStruct
{
fixed int fiveArrays[5];
}

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
Daniel,
2. I was reading an older(circa 2000) question[1] posted to one of these
groups in which Eric Gunnerson mentions that the C# team was still talkingabout a way to declare inlined arrays of base types in structures,
basically:
struct myStruct
{
int[5] fiveArrays; //5 ints all in a row in memory, obviously would needbetter syntax
}
out of my own curiosity, has anything about this come up recently? Is the
team still considering it? Is something perhaps coming up(or is there
something there in 1.1 I've not managed to find?).

It's planned for v2.0 (Whidbey), with the syntax

struct myStruct
{
fixed int fiveArrays[5];
}


Good to hear, I havn't had the time to read everything on the new C# specs.
Interestingly, this is one feature I never use but always miss.

Thanks

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 15 '05 #3
Daniel,
Good to hear, I havn't had the time to read everything on the new C# specs.
IIRC the preliminary spec they published only covered the four new big
features (generics, partial types, iterators and anonymous delegates).
There are more little things being added as well. You can see them at
the end of Anders Hejlsberg's PDC slides (session TLS320) at

http://msdn.microsoft.com/events/pdc...s/default.aspx

Interestingly, this is one feature I never use but always miss.


It will probably mostly be used in interop situations. It's limited to
the primitive value types, and I believe it only works in an unsafe
context. There's no runtime support for it, so they implement it by
generating a nested opaque value type of size
sizeof(elementType)*numElements, include a field of that type in place
of the fixed array, and then index into that with pointer offsets.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #4

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
Daniel,
Good to hear, I havn't had the time to read everything on the new C#
specs.
IIRC the preliminary spec they published only covered the four new big
features (generics, partial types, iterators and anonymous delegates).
There are more little things being added as well. You can see them at
the end of Anders Hejlsberg's PDC slides (session TLS320) at

http://msdn.microsoft.com/events/pdc...s/default.aspx Hrmm, I find it interesting that there has been less coverage on some of
these minor features added to the language. the namespace alias qualifier
looks interesting, as does the addition of static classes. Every forum,
newsgroup, mailing list, etc I read has been up in arms over generics and
iterators, but they say very little about some of these other features that,
while not massive, are still interesting.
Interestingly, this is one feature I never use but always miss.
It will probably mostly be used in interop situations. It's limited to
the primitive value types, and I believe it only works in an unsafe
context. There's no runtime support for it, so they implement it by
generating a nested opaque value type of size
sizeof(elementType)*numElements, include a field of that type in place
of the fixed array, and then index into that with pointer offsets.

Thats basically what I was considering using it for, unsafe code. The
thought came up most recently when I was faced with the possible need to
write an ISO-9660 image reader class, and the thought came to me to use
unsafe code to map to the headers for reasons explainable only by having
spent enough time in C that pointers just wont' stop dancing around in my
head. That basically illustrates my point, I've thought about the need for
inline arrays in structures a number of times, and in the vast majority of
them I realize that they wouldn't be a good way to go even if it was
possible currently, thus a feature I would very rarely use but would always
miss, because I know that eventually I am going to need it for something.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 15 '05 #5
Daniel,

It's been a while since we did stackalloc, but IIRC, we only allowed it as
an initialization because we wanted to limit the impact that it would have
on the language.

To answer your other question about when we'll be talking about other
features, we're working on a merged version of the language spec (new
features + old features), and we're also working on a "what's new in C#"
spec.

Both should show up on the C# dev center on MSDN. The second one should (and
I don't own it....) be up there in the next week or so.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Two questions here:

1. Is there any particular reason why when using stackalloc, the code byte
*buffer = stackalloc byte[50]; works, but code like byte *buffer; buffer =
stackalloc byte[50]; is considered incorrect syntax? Was this an oversight, a stylistic design, or is there a technical reason it won't work?

2. I was reading an older(circa 2000) question[1] posted to one of these
groups in which Eric Gunnerson mentions that the C# team was still talking
about a way to declare inlined arrays of base types in structures,
basically:
struct myStruct
{
int[5] fiveArrays; //5 ints all in a row in memory, obviously would need better syntax
}
out of my own curiosity, has anything about this come up recently? Is the
team still considering it? Is something perhaps coming up(or is there
something there in 1.1 I've not managed to find?).

1. http://tinyurl.com/vi0s

Nov 15 '05 #6

"Eric Gunnerson [MS]" <er****@online.microsoft.com> wrote in message
news:OI**************@tk2msftngp13.phx.gbl...
Daniel,

It's been a while since we did stackalloc, but IIRC, we only allowed it as
an initialization because we wanted to limit the impact that it would have
on the language.

Interesting. stackalloc was about the only keyword I had any trouble with.
When I first came across it and started playing with it, I managed to miss
the requirement that it only be used in an initalization. So, I'm sitting
there wondering why exactly visual studio and the spec mentions this
keyword, but the compiler won't accept it. It took a bit to figure out.
To answer your other question about when we'll be talking about other
features, we're working on a merged version of the language spec (new
features + old features), and we're also working on a "what's new in C#"
spec.

Both should show up on the C# dev center on MSDN. The second one should (and I don't own it....) be up there in the next week or so.
I'll keep my eyes open, thanks for the info.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights. "Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Two questions here:

1. Is there any particular reason why when using stackalloc, the code byte *buffer = stackalloc byte[50]; works, but code like byte *buffer; buffer = stackalloc byte[50]; is considered incorrect syntax? Was this an

oversight,
a stylistic design, or is there a technical reason it won't work?

2. I was reading an older(circa 2000) question[1] posted to one of these
groups in which Eric Gunnerson mentions that the C# team was still talking about a way to declare inlined arrays of base types in structures,
basically:
struct myStruct
{
int[5] fiveArrays; //5 ints all in a row in memory, obviously would

need
better syntax
}
out of my own curiosity, has anything about this come up recently? Is the team still considering it? Is something perhaps coming up(or is there
something there in 1.1 I've not managed to find?).

1. http://tinyurl.com/vi0s


Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Spammay Blockay | last post by:
I've been tasked with doing technical interviews at my company, and I have generally ask a range of OO, Java, and "good programming technique" concepts. However, one of my favorite exercises I...
2
by: Ross Micheals | last post by:
All I have some general .NET questions that I'm looking for some help with. Some of these questions (like the first) are ones that I've seen various conflicting information on, or questions that...
1
by: S Austin | last post by:
Discovered recently (duh) that putting inline code in .h files (e.g. in class definitions) is not a good idea when building DLLs and the applications that use those DLLs. The reason being, of...
12
by: prashna | last post by:
Hi Guru's, Here are my questions... 1)Why does c allows an extra "," in array intialiser?Is there any advantage of this? ex: int arr={1,2,3,4,5,}; ^^Compiler does not give error for this! ...
7
by: Rano | last post by:
/* Hello, I've got some troubles with a stupid program... In fact, I just start with the C language and sometime I don't understand how I really have to use malloc. I've readden the FAQ...
7
by: Victor S. | last post by:
1. What is System.Windows.Forms.VisualStyles.TextMetricsCharacterSet good for? 2. Are the Indic scripts supported? Are all supported scripts fully supported? (for printing and fine measuring)...
27
by: fctk | last post by:
hello, i have some questions. 1) do constant expressions include string literals? for example, is "hello, world" a constant expression? 2) int i = 0; is the equal sign the assignment...
11
by: efrat | last post by:
Hello, I'm planning to use Python in order to teach a DSA (data structures and algorithms) course in an academic institute. If you could help out with the following questions, I'd sure...
7
by: valentin tihomirov | last post by:
Typically, you need the stackalloc when using win32 platform fucntions, which tell you the amount of memory required for the output structure in the first call, like GetJob does. The weired thing...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.