473,788 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

definition/explanation of an unboxed array in c is ...?

ben
i was reading this page "Optimizing Machine Learning Programs"
http://hunch.net/?p=290 where in the comments at the bottom regarding
the third point "Avoid Pointer-Based Representations " there is talk of
unboxed arrays.

having done a bit of searching i have now have a rough idea of what
unboxed variables are. generally they seem to be primative variable
types like int and float where the value in question is right there,
not referrenced by a pointer which points to the value in the heap. so
is an unboxed variable one which is local and on the stack? also in c,
so far as arrays go, would an unboxed array be one that is only on the
stack? do unboxed arrays never exist on the heap?

thanks.

Sep 30 '07 #1
6 2177
ben
or is "unboxed" and "unboxed arrays" not really applicable to c ?

Sep 30 '07 #2
In article <11************ **********@r29g 2000hsg.googleg roups.com>,
<be*@mailinator .comwrote:
>i was reading this page "Optimizing Machine Learning Programs"
http://hunch.net/?p=290 where in the comments at the bottom regarding
the third point "Avoid Pointer-Based Representations " there is talk of
unboxed arrays.
I think you may have misinterpreted this. As far as I can tell,
they're not contrasting "boxed arrays" and "unboxed arrays", but boxed
representations - typed objects, which point to each other - with
arrays.

I take the term "unboxed array-base implementations " to mean "unboxed
(i.e. array-based) implementations ".

I haven't read the article in detail.

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Sep 30 '07 #3
be*@mailinator. com wrote:
or is "unboxed" and "unboxed arrays" not really applicable to c ?
"Unboxed" and "boxed" aren't C terms. In some object-
oriented languages, they refer (usually informally) to
simple primitive variables and to full-fledged objects,
respectively. In Java, for example, a `float' variable is
a primitive and a `Float' is an object with a `float' hidden
("boxed") inside it. (Why bother? Because an object is an
instance of a "class," and the class provides "methods" that
code can use without necessarily being fully aware of exactly
what kind of object is at hand. This is said to promote code
reuse; IMHO "promote" is some distance short of "guarantee. ")

C has "objects," but not in the way O-O languages use the
term. C's objects are passive receptacles for values; an O-O
language would probably call them primitives or aggregates of
primitives. In other words, all C variables of all kinds are
"unboxed," and there is no way to "box" them.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Sep 30 '07 #4
ben
ok, thanks v. much for the replies.

Sep 30 '07 #5
"Eric Sosman" <es*****@ieee-dot-org.invalidwrot e in message
be*@mailinator. com wrote:
>or is "unboxed" and "unboxed arrays" not really applicable to c ?

"Unboxed" and "boxed" aren't C terms. In some object-
oriented languages, they refer (usually informally) to
simple primitive variables and to full-fledged objects,
respectively. In Java, for example, a `float' variable is
a primitive and a `Float' is an object with a `float' hidden
("boxed") inside it. (Why bother? Because an object is an
instance of a "class," and the class provides "methods" that
code can use without necessarily being fully aware of exactly
what kind of object is at hand. This is said to promote code
reuse; IMHO "promote" is some distance short of "guarantee. ")

C has "objects," but not in the way O-O languages use the
term. C's objects are passive receptacles for values; an O-O
language would probably call them primitives or aggregates of
primitives. In other words, all C variables of all kinds are
"unboxed," and there is no way to "box" them.
Though the equivalent would be, for say a list of x, y, z co-ordinantes

float **coords;

as opposed to

float coords[100][3];

A more illuminating example might be a tree.

typedef struct node
{
struct node *left;
struct node *right;
double data;
}
is the obvious way to do it.

However

struct node
{
int right;
int left;
double data.
};

struct tree
{
struct node nodes[100];
/* left and right index into this array */
};

will tend to produce fewer pointer dereferences and execute faster.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Sep 30 '07 #6
"Malcolm McLean" <re*******@btin ternet.comwrite s:
"Eric Sosman" <es*****@ieee-dot-org.invalidwrot e in message
>be*@mailinator. com wrote:
>>or is "unboxed" and "unboxed arrays" not really applicable to c ?

"Unboxed" and "boxed" aren't C terms. In some object-
oriented languages, they refer (usually informally) to
simple primitive variables and to full-fledged objects,
respectively .
<snip succinct explanation of boxed and un-boxed types>
Though the equivalent would be, for say a list of x, y, z co-ordinantes
<snip>
A more illuminating example might be a tree.

typedef struct node
{
struct node *left;
struct node *right;
double data;
}
is the obvious way to do it.

However

struct node
{
int right;
int left;
double data.
};

struct tree
{
struct node nodes[100]; /* left and right index into this array */
};

will tend to produce fewer pointer dereferences and execute faster.
....but also represents a different structure. I suspect the OP will
stare at this and be baffled as to how these two represent boxed and
un-boxed versions of some type.

In a boxed type, it is usual to find the same data inside. You could
have illustrated it with a raw array:

float data[100];

vs. a "boxed" version with high-level access operations:

Array *make_array(siz e_t n);
void set(Array *a, size_t elem, float value);
float get(Array *a, size_t elem);
float sum(Array *a);

but even this is rather confusing because everything has to be "done
by hand" in C since there is no native language equivalence of boxing
a type.

--
Ben.
Oct 1 '07 #7

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

Similar topics

4
2164
by: Gianni Mariani | last post by:
I posted a gcc bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13332 here is the text: ----------------------------------------------------------- This code will compile fine but fail on a linker error.
3
1593
by: Robert Neville | last post by:
I am looking for JavaScript examples on expanding contextual definition. For example, you have a word like POP3 and the user click on the word expanding it with the following contextual definition. POP3 (POP3: A common protocol that is used to retrieve e-mail messages from an Internet e-mail server.) Sites like Microsoft use the technique throughout their site. I hope to find the code and an explanation on its usage. Let me know if you...
6
1961
by: Buck Rogers | last post by:
Hi guys! Love your work! The below program is from K&R2, p22. ================================= #include <stdio.h> /* count digits, white space, others */ main() {
10
20893
by: Kobu | last post by:
My question is about the use and meaning of the terms "declaration" and "definition" as it pertains to the C language. I've read sources that mix the two up when talking about such things as setting aside storage for an object, defining/declaring a struct, parts of a function, referencing an external variable in another module. sourcefile1.c ============== extern long globalfoo; /* declaration? */
11
5590
by: tony.fountaine | last post by:
I don't think this is possible but, if anyone has comments on a work around that would be great. Let me explain the reason I would like to do this. Suppose you are given a file that contains a header defining a structure for a set of data that is contained in the file. If you do not know what the structure is before you read the header of the file how would you work with this in code? Any comments would be greatly appreciated.
9
9420
by: joshc | last post by:
Hi, I have an array defined in one file with an intializer as follows: int arr = {0, 1, 2, 3}; I have a declaration of the array in another file as follows: extern int arr;
9
5097
by: gopal | last post by:
Why is ; ~ semi-colon used at the end of class definition ? Thanks JK
15
1668
by: mdh | last post by:
May I ask. If an array is defined , not as a static, but outside of a function, is there any guarantee as to the contents of each element? Thanks.
275
12406
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6750
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.