[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y / ] [Home]
4chanarchives logo

/dpt/ - Daily Programming Thread


Thread replies: 341
Thread images: 18

File: K&R himegoto waifux2.png (1MB, 1000x1400px) Image search: [Google] [Yandex] [Bing]
K&R himegoto waifux2.png
1MB, 1000x1400px
old thread: >>54651035

What are you working on, /g/?
>>
First for web development
>>
First for /wdg/ is the /dpt/ for the 21st century.
>>
nothing, too depressed to work on anything.
>>
>>54653610
kill yourself

>>54653617
kill yourself

>>54653629
kill yourself

>>54653632
don't kill yourself

>>54653638
kill yourself
>>
>>54653610
Thank you.

nth for C#.
>>
>>54653626
>django skills

I work in webdev writing backend software in Go and Java. While you're deprecated, I'm going to be raking it in until I retire :^)
>>
>>54653657
>i'm a delusional FAG
kill yourself
>>
>>54653664
>Java
I'm sorry. How do you cope?
>>
>>54653664
>django
>deprecated
Nice meme
>>
>>54653664
yeah you sure are developing those bleeding edge algorithms and shit to move that database crap around
>>
>>54653674
Java isn't the most horrible thing in the world.

It sure ain't good, though.
>>
>>54653682
say that to the guy I was replying to

>>54653674
I don't sperg out when I have to write code because I realize that all programming languages are pretty much the same. A good IDE can make even Java a joy to program in.

>>54653691
Heh, at least I have a job that I enjoy my man. Do you?
>>
>>54653709
>I don't sperg out when I have to write code because I realize that all programming languages are pretty much the same.
Even COBOL?
>>
>>54653709
>say that to the guy I was replying to
My bad homie.
>>
File: akari2.jpg (58KB, 514x524px) Image search: [Google] [Yandex] [Bing]
akari2.jpg
58KB, 514x524px
pls rate my dumb music program~
pipe the output to your sound card!
unsigned char b[], r1[], r2[];/* run: 'gcc -o pcm pcm.c && ./pcm | aplay' */
main(p,c,m){p=0,c=1;while(1){for(m=0;m<10000;m++){unsigned char*a=(c)?r1:r2;
putchar(((char)((float)(*(a+m)+*(b+m))/2.0)));}if(p++>2){p=0;c=!c;}}}/* <3 */

full program here -> https://a.pomf.cat/vbrtpq.c
>>
>>54653665
being into traps in not gay tho
>>
>>54653729
Looks like a meme
>>
>>54653720
Actually yes. Programming is 70% thinking and 30% actually writing code. If what you're thinking about is cool enough, then writing it will be fun no matter what language it's in. If you derive joy from looking at MUH SYNTAX or this or that then you're not doing it right
>>
>>54653729
>deletes first post to repost with a blank image
Looks scary, is that an viruses?
>>
>>54653698
omg how do I get my system32 back
>>
>>54653698
>>54653729
>undefined behavior
m8...
>>
>>54653729
>it does sudo rm -rf
no thx
>>
>>54653751
nothing is fun in python if you know anything about programming and comp sci
>>
Hey gee, how do I allocate a 2d array on the heap?
>>
Hey gee, how do I average 2 numbers?
>>
>>54653779
malloc(rows * cols * sizeof(cell))
>>
Hey gee, why don't you EOF?
>>
File: 1458235978264.png (515KB, 543x417px) Image search: [Google] [Yandex] [Bing]
1458235978264.png
515KB, 543x417px
>>54653610

Writing a router for javascript. Figured why the fuck not, might as well. Close to being done.

Though, like with all other personal projects, I probably will take another 2 weeks to finish it off because I'm too lazy to dedicate time to my own projects.
>>
Hey gee, can you guess the size of my dick?
>>
>>54653779
int (*arr)[8] = malloc(sizeof(int[8][8]));
>>
>>54653779
>>54653789
>>54653806
>>54653817
kys

>>54653755
>loonix
>system32
>>
>>54653819
>latest clang tho
>700.1.18
>>
Fuck GTK and fuck Glade.
>>
>>54653834
>giving a flying fuck about clang
>>
>>54653835
Fuck you for not using Qt.
>>
>>54653751
Would you rather drive an average car from 2000 or an average car from 1900?
>>
>>54653833
>not running the Linux subsystem for Windows 10

???? just do the needful and tell me how to get it back
>>
>>54653833
>dunno
>dunno lel
>what is EOF
>huge, you raped me a lot
:^)
>>
So apparently vectors are better than linked lists.
>>
>>54653850
>>54653819
>>
>>54653840
I wish I could but I can't. I'd have already finished what I need to do with Qt but with GTK I can't even get started.
>>
>>54653854
>apparently
just
>>
>>54653858
>muh xcode warnings tho
>>
File: you-dont-say.jpg (19KB, 500x280px) Image search: [Google] [Yandex] [Bing]
you-dont-say.jpg
19KB, 500x280px
>>54653854
>So apparently <anything> are better than linked lists.
>>
>>54653893
>memejs brogrammer
please
>>
>>54653890
>giving a flying fuck about xcode

>>54653908
>ever using linked lists
please
>>
>>54653913
>I can't into linked lists
you're simply not a real programmer m8; I expect you're also not into traps, right?
>>
I tried to compile this code but the latest GCC on my RHEL 4 gives me a warning.
void f(int x) {
int y[x];
}

What's going on guys?
>>
>>54653946
same with my latest GCC on my slackware 2.0
>>
What do I call a thing a player can "use"? (eg weapons, keys, food)

Tool and gadget come to mind but it doesn't seem right.
>>
>>54653960
object
>>
>>54653946
my guess is that y's index doesnt exist yet
>>
>>54653960
item
>>
>>54653960
public interface IPlayerUsable {}
>>
>>54653964
Doesn't sound right either, object can also be a rock, statue, woman, etc.
>>
>>54653939
there is no valid use case for linked lists, they're inferior in every way to arrays
>>
>>54653976
>my guess
guessing might work with html and css
>>
>>54653983
kys
>>
>>54653993
>I'm simply retarded, no point in trying to explain anything to me
ok
>>
>>54653960
Consumable
>>
>>54653993
There are some use cases.
>>
>>54653979
This might be the word I'm looking for.

>>54653983
Ew.
>>
>>54654015
>animuuuuuuuuuu
>>
>>54654016
if you knew linked lists you would know they're shit

>>54654020
not really
>>
>>54654025
>really, I'm literally retarded and you can't expect meaningful discussion
>>
>>54654019
>Consume a weapon
>>
>>54654024
>disgusting C#
>microcock-approved systems hungarian
cancer
>>
>>54654025
There are only 2 scenarios where linked lists shit all over anything else.
>>
>>54654038
you sure presented a solid case for linked lists
>>
>>54654025
>not really
There are tho.
>>
File: 1460115987647.png (30KB, 246x200px) Image search: [Google] [Yandex] [Bing]
1460115987647.png
30KB, 246x200px
>>54654021
Item is your best bet because it's all-encapsulating; item can be broken down into:
- weapon
- attire/armor
- key (access)
- consumable

>>54653983
>PlayerUsable
>>
>>54654054
>presenting a solid case to self proclaimed retards
lad...
>>
>>54654050
>>54654057
shouldn't be hard to fill in the blanks then

list of valid use cases for linked lists:
>
>
>>
>>54654083
condition variables
>>
>>54654083
teleportation of data across mainframes
>>
File: 1463711688377.png (206KB, 2126x1116px) Image search: [Google] [Yandex] [Bing]
1463711688377.png
206KB, 2126x1116px
>>54653610
is there anything like "portfolio" for a software developer ? I mean for a /wdg/ its easy peasy but for undergraduate cs meme whats the min requirements to get a job without previous exp in the field ?

Thats what I need, just get at least 6 months even for a shitty pay or no pay at all and then put it on my resume but I have no other exp b4 that.

However I did all the fizzbuzz shit and stuff like pic related, does this skill level matches the Junior position in most places ?
>>
>>54654083
rekerneling the haskell in the haskell kernel
>>
>>54654083
When the size of the element is getting up to a few kb or so.
>>
>>54654128
well a portfolio for a software dev now a days is a github account with projects you contribute to.
>>
File: snap_09.png (80KB, 1218x652px) Image search: [Google] [Yandex] [Bing]
snap_09.png
80KB, 1218x652px
>>54653610
I'm doing the Matasano crypto challenge, just finished Set 3.
Most challenges are pretty simple at the start, but I love that some of them are actually challenging.

Fun stuff to do while waiting for the Stockfighter guys to release their thing.

http://cryptopals.com/
>>
>>54654153
What the fuck?

How can you stand to look at that?
>>
>>54654128
Junior positions only require a degree.
If you want to stay ahead of the competition, create a github account and randomly fork popular repos.
>>
>>54654159
If you start talking shit about my fonts, I swear...

I'm font blind, it could be Comic Sans and I wouldn't notice.
>>
>>54654128
Something with some sort of interface is the most obvious, be it command line or something like Qt/GTK/WPF/Windows/etc. In any case you need links to repositories so if you only have a couple "visually presentable" projects that you can bring people to get to anything more impressive that isn't, then that will suffice.
>>
>>54654168
It's not just the font, it's the garish contrasting colors and the literal black background.

It's visually offensive.
>>
>>54654153
what font is that?
>>
>>54654168
I think anon means the cancerous color scheme.
>>
>>54654143
then you use a contiguous array of pointers
>>
>>54654153
I've been looking for a font like that for a long time.
>>
>>54654083
>retard pretends to have the mental capacity to understand reason
>>
>>54654145
>>54654162
yeah I have one, I used Java, C# and C++ for different stuff ( Made a simple game in C# and a database with Java and C++ I used for OpenCV project linked to a data base for the old work I had where we needed to calculate a volume and surface area out of a vector image, anyway... ) but I dont think they are serious enough, and besides the porjects we had at uni I never actually worked with other ppl in team.
>>
>>54654221
xD
>>
>>54654179
>>54654187
>>54654186
>>54654209
Oh come on.

The color scheme is something that doesn't destroy my eyes at night + vim's color_coded.

The font is Deja Vu Sans Mono w/ the Vim Powerline patch.
>>
>>54654221
>he believes in retarded bullshit that goes against industry wide accepted wisdom and common sense
>he has nothing, not even a single use case to back up his claim
>>
File: 1460618586166.jpg (92KB, 500x367px) Image search: [Google] [Yandex] [Bing]
1460618586166.jpg
92KB, 500x367px
>>54654162

>If you want to stay ahead of the competition, create a github account and randomly fork popular repos.

Has that ever worked?
>>
>>54654236
>doesn't destroy my eyes at night
Yeah, nah.

Bright Yellow, Neon Cyan, and Fuck-My-Boypussy Purple against a stark black background is almost as bad as a white background with black text.
>>
>>54654162
>If you want to stay ahead of the competition, create a github account and randomly fork popular repos.
Lolno. If you want to be ahead, *create* popular repos.
Stars is all you should care about if GitHub is your CV.
>>
>>54654195
Also known as a linked list.
>>
>>54654288
that's not even remotely what a linked list is you dip
>>
>>54654301
Yes it is.
>>
>>54654312
fuck off this is just too retarded
>>
Is there a reason to use anything but utf8 in the current year?
>>
>>54654250
>industry wide
>wisdom
you mean memejs and CSS cucks? that industry?
top fuckin kek!
>>
File: snap_11.png (81KB, 1345x654px) Image search: [Google] [Yandex] [Bing]
snap_11.png
81KB, 1345x654px
>>54654276
The pastel colors are so it has good contrast against the black background, which means I can lower my screen luminosity all the way and still see shit, and even after my eyes are super tired it's very easy to parse.

It Works For Meâ„¢
>>
>>54654344
yes
>>
>>54654374
>pastel
That word does not mean what you think it does.
>>
>>54654236
>Deja Vu Sans Mono
Damn that font doesn't render like that at all on my machine.
>>
Any reason not make every function possible take references? I mean I pass a var to a func that only reads var, I might as well take a reference to var assuming it's a thread safe environment?
>>
>>54654344
Yes.

UTF-8 uses more space than UTF-16 in some situations.
>>
>>54654374
>see shit
got that right!
>>
>>54654371
>low effort trolling
>>
>>54654398
Yes.

No.
>>
File: snap_12.png (36KB, 624x563px) Image search: [Google] [Yandex] [Bing]
snap_12.png
36KB, 624x563px
>>54654385
Ok, /gd/, then call it bright if it makes you happy.

>>54654386
I downloaded it there: https://github.com/powerline/fonts
Picrelated.
>>
>>54654398
pass by value > pass by reference > pass by pointer
>>
>>54654419
Why not?
I'd say it's worth it to shave off some memory copying.
>>
>>54654416
>I got told
we know, m8, we know
>>
>>54654436
you're the one who got told, you still haven't presented a single reasonable use case for linked lists
>>
>>54654083
When data needs to be in multiple lists, or when building up shared data between multiple threads (swing a pointer to a new node with atomics to publish data).
>>
>>54654427
>then call it bright if it makes you happy.
I typically use an accepted English work to describe a particular quality of a thing, rather than using words that mean the opposite of what I am trying to convey.
>>
>>54654431
>pass by reference > pass by pointer
they're the same thing, mong
>>
>>54654153
very pretty, i wish most code i worked with was written that clearly

it is really sad how few programmers understand formatting their code to be readable
>>
>>54654463
>C is all i know
no they're not
>>
>>54654460
>English work
HAHA TYPO
>>
>>54654398
It's less efficient for smaller types which can fit in a register or two.
>>
>>54654451
>no u
retard confirmed
>>
>>54654471
you should learn more
>>
>>54654477
shouldn't you be programming or something
>>
>>54654488
>no bully
:^)
>>
>>54654485
if YOU learned more you would know that in based C++ they're completely different things retard
>>
>>54654463
lol
>>
>>54654488
no. that's what my employees do
>>
>>54654503
>completely different
you are wrong, but then again you're a webshit and I'm a big dick playa...
>>
>>54654520
fuck off tard you're not even funny, you're just saying blatantly false things
>>
>>54654470
Yeah... See I actually think that code was disgusting. I usually try to write cleaner than that.

I wrote it as a one off script just for the challenge, so it's kinda unreadable.
It needs a bit more spacing between logical blocks, some of it desperately needs to be pulled into its own functions, and a couple strategicly placed comments would be nice, and the 5 indentation levels with i,j,k iteration variables make me want to stab myself in the hand.
>>
>>54654527
>stop raping me
mkay, laddie :^)
>>
>>54654503
They are semantically equivalent from the business logic pov.
They only differ in particular language constructs like copy constructors, decltype and other type deduction stuff.
>>
>>54654527
>defensive
You literally got told!
>>
Hey /dpt/, which do you prefer? Why?
{
if (...) {
...;
return ...;
} else {
...;
return ...;
}

or
{
if (...) {
...;
return ...;
}
...;
return ...;
}
>>
>>54654583
Neither.

Allman brackets, please.
>>
>>54654583
It's a semantic difference for me.

If the "if" is an exceptional case, then use the 2nd so the normal path isn't in a else.
If both cases are normal, the 1st makes more sense.
>>
>>54654583
The latter.
I hate extraneous syntax which serves no purpose.
>>
def is_identity_matrix(matrix):
col = zip(*matrix)
n = 1
m = 1
z = 0
lst = []
if col[0][0] == 0:
return False
exit()
while n < len(col[0]):
if col[0][0] > 0:
lst.append(col[n][m])
n += 1
m += 1
while z < (len(matrix[0]) * len(matrix[0])):
z += 1
if not matrix[z].count(1) > 1 and all(lst) >0:
return True
return False
def is_identity_matrix(matrix):
col = zip(*matrix)
n = 1
m = 1
z = 0
lst = []
if col[0][0] == 0:
return False
exit()
while n < len(col[0]):
if col[0][0] > 0:
lst.append(col[n][m])
n += 1
m += 1
while z < (len(matrix[0]) * len(matrix[0])):
z += 1
if not matrix[z].count(1) > 1 and all(lst) >0:
return True
return False

matrix1 = [[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[0,0,0,1]]
print is_identity_matrix(matrix1)

Im getting ValueError: list.remove(x): x not in list
I dont understand why
>>
>>54654583
2nd.
Reduce indentation as much as you can.
>>
>>54654617
If only developers had you abstraction skills.
>>
Someone gave me some snippets to some array system for C awhile go, and i've been working on something that lets me queue SDL_Texture's into an array.

//array.h
void *array_add ( Array *arr );
#define array_add_val(type, arr) (*((type *) array_add(arr)))


//array.c
void *array_add ( Array *arr )
{
if ( ++arr->length > arr->capacity )
arr->buf = realloc( arr->buf,
arr->element_size * (arr->capacity = arr->capacity << 1) );

return arr->buf + arr->element_size * (arr->length - 1);
}


//texture.h
typedef struct
{
unsigned int ID;
SDL_Texture *txr;
unsigned int w;
unsigned int h;
} TxrArr;

Array *G_txr;


//texture.c
void texture_add ( char *filename )
{
SDL_Texture *t = NULL;
t = textureLoad( filename );

unsigned int ID = texture_generate_id();

unsigned int w = getTextureW(t);
unsigned int h = getTextureH(t);

array_add_val(TxrArr, G_txr) = (TxrArr) { ID, t, w, h };
}


I didn't post everything but I will post more if you need it.

my getTexture functions just run SDL_QueryTexture and return the value, they work. BUT, they don't store in texture array that's just made. A workaround is to add this to the bottom of the texture_add function

TxrArr *p = array_get ( G_txr, ID ); 

p->w = w;
p->h = h;

p = NULL;


It seems unnecessary, but it's the only way I can actually force those values to be set lol.
>>
>>54654143
>>54654455
Vectors of pointers aren't linked lists.
>>
>>54654650
Cmon if you're going to ask for tech support, at least use code tags...
>>>/faq/
>>
>>54654620
>>54654652
Code monkeys will always code monkey. That's a fact.
>>
LEGIT DYNAMIC CONTIGUOUS MULTIDIMENSIONAL ARRAY EVERYONE

RETARDED C SPERGS BTFO, CAN'T EVEN USE 2D ARRAYS, THEY UNIRONICALLY USE 1D ARRAYS AND INDISCRIMINATELY RECOMMEND THEM TO OTHERS

http://ideone.com/FgqWv9
>>
>>54653983
>>54654039
Why one interface? Food is Consumable, weapons are Wieldable, and keys are Usable. I guess Consumable and Usable could be coalesced and return whether they should be consumed or not, but that depends on other things.
>>
>>54654677
>int *arr[4] = *x;
You realize that this line makes no fucking sense, right?
>>
>>54654677
That's not a dynamic 2D array.
>>
>>54654732
yeah whatever i was just experimenting, just running it publishes its, refresh the page

>>54654738
yes it is
>>
>>54654744
>yes it is
No, both dimensions are fixed.
>>
>>54654667
>C
>>
>>54654760
the dimensions can be variable
>>
>>54654677
>THEY UNIRONICALLY USE 1D ARRAYS AND INDISCRIMINATELY RECOMMEND THEM TO OTHERS
Because they are more efficient.
>>
#include <iostream>
#include <stdlib.h>
using namespace std;
void foo(int m, int n) {
int (*x)[m][n] = (int (*)[m][n]) malloc(sizeof(int[m][n]));
*x[0][0] = 0;
*x[0][1] = 1;
*x[0][2] = 2;
*x[0][3] = 3;
*x[1][0] = 4;
cout << **(*x + 0) << endl;
cout << **(*x + 1) << endl;
cout << **(*x + 2) << endl;
cout << **(*x + 3) << endl;
cout << **(*x + 4) << endl;
}


get rekt C TARDS i'm beating you at your own game
>>
>>54654677
>C++
>malloc

Hitlerally why
>>
>>54654807
no they're not, contiguous 2d arrays have zero overhead over 1d arrays, and the only reason the original tard recommended them was so that it could be zeroed using one call to memset

>>54654829
nice meme
>>
>>54654814
That's C++, not C.
>>
>>54654846
the array part applies to C too you complete moron, the only thing specific to C++ is the printing shit
>>
>>54654844
>no they're not,
Yes they are.
>contiguous 2d arrays have zero overhead over 1d arrays,
Pointer to a 2D array has an extra level of indirection.
>>
>>54654872
all relevant benchmarks show that 1d arrays are either no faster than or actually slower than 2d arrays
>>
>>54654693
For inheritance.
A class Item can serve as a base for Weapon, Food, Key. This way the Player class can have an Item* "WieldingItem" and if the player clicks their mouse, it can do "WieldingItem->Use()".
Language being C++
>>
>>54654897
and this is still way faster than the cancerous many-malloc array of arrays shit that FUCKING RETARDED C TARDS insist are multidimensional arrays
>>
Wincucks: does Windows support forward slashes as a path separator?
>>
>>54654814
I'm not convinced casting an int* of size m*n to a (int(*)[m][n]) is not somehow UB on a theoritical C machine.
I'm thinking that there could be some theoritical alignment shenanigans.
>>
>>54654902
I'm not stupid, I'm asking why you feel the need to shoehorn fundamentally different things under a single interface. Unless you mean to only make weapons "usable" in the sense that "using" them just equips them.
>>
>>54654926
yes
>>
>>54654926
yeah
>>
>>54654897
Nope.
1D arrays cannot possibly be slower you retard, what do you think the 'contiguous' part actually means?
And another level of indirection is always slower (grantd it's a microscoping difference, but it's there)
>>
>>54654926
No.
t. Linux user.
>>
>>54654931
the void pointer from malloc can be cast to anything
>>
>>54654947
a 2d array is accessed the same way as you'd access a 1d array, it's syntactic sugar for the same thing
>>
>>54654953
Try casting it to a function pointer then.
>>
>>54654926
Every version of Windows, and every version of MS-DOS from 2.0 on,
has accepted "/" as a path delimiter.
>>
>>54654981
Exactly, except with a pointer to a 2D array you have one more dereference, which is one more load instruction and memory access.
>>
>>54654986
that doesn't have anything to do with anything, you can always cast void* to pointers to other data types, in C you don't even cast malloc it's all handled implicitly, fucking clueless C tard how can you not know this

>>54655004
there is not an extra dereference, it's the same as emulating a 2d array with a 1d array, it's how the implementation works behind the same, it's just syntax
>>
>>54655013
>behind the same
behind the scene
>>
>>54654937
>>54654941
>>54655000
Thanks family.
>>54654952
Kill yourself.
>>
>>54655013
>that doesn't have anything to do with anything
It has to do with the C standard being more complicated than you think. If you cast malloced memory to a function pointer and do anything with it, that's automatically undefined behavior.

>you can always cast void* to pointers to other data types, in C you don't even cast malloc it's all handled implicitly, fucking clueless C tard how can you not know this
It's possible you're right, but I wouldn't bet on it with all that Dunning-Kruger you're showing off.
>>
>>54655013
>there is not an extra dereference,
Yes there is, go look at the disassembly for:
(*a)[y][x] vs *(a + y*N + x)
>>
>>54654932
Because it makes sense from a design standpoint to have an "Item" and have "Weapon", "Hammer", "Sword" derive from it, it allows for cleaner and more understandable code compared to having Weapon, Hammer, etc not be derived from anything.
>>
>>54655043
>It's possible you're right, but I wouldn't bet on it with all that Dunning-Kruger you're showing off.
how else would it work dumbass, how would you malloc anything if you're not allowed to cast from void pointer
>>
>>54655057
>it allows for cleaner and more understandable code
There's nothing about "deriving everything from a single base class" that inherently makes your code better. In fact, it usually has the opposite effect, because you end up with a monolithic blob for your base class, or conversely, a base class so restricted that you need to downcast to get anything done.
>>
In tkinter, is it possible to have some function that does all of the following:

- spawn a new window with a text entry field
- get the user's input once they press return
- text entry window destroys itself and returns the entered value to whatever called it

So I could just do something like

text = GetUserInput()

Where GetUserInput handles making the new window, binding a method to it, receiving the user input, and then returns the value.

I'm stuck on what has to return where because making the new text entry window involves instantiating a new class and it doesn't seem like you can return a value from __init__.
>>
>>54655072
You're allowed to cast from void*, with some exceptions.
Function pointers are one of those exceptions because it breaks a different casting rule. It's not at all obvious that casting int* to int(*)[][] does not break any rule anywhere.
>>
>>54655101
it's not a function pointer
>>
File: Prophet_Mohammad.jpg (2MB, 3120x4160px) Image search: [Google] [Yandex] [Bing]
Prophet_Mohammad.jpg
2MB, 3120x4160px
>>54654829

Reasons to use malloc in C++:

1. Using a library function that requires a malloc allocated buffer. Not common, but I've seen it happen at least once... somewhere.

2. The new and delete operators will invoke an object's constructor and destructor respectively. If one wishes to delay object initialization for some reason, an alternative allocator may be a better idea. That said, if you don't want RAII, it begs the question as to why you are using C++. And also, one can always define a constructor and destructor to do nothing.
>>
>>54655123
Damn you're pretty dense, aren't you?
All the "lol u guys r dumb" crap already made that clear, but you must like to lay it on thick.
>>
>>54655134
it's clearly not a function pointer for fuck's sake, where are the parameters?
>>
>>54655131
new doesn't allow dynamic allocation of a contiguous 2d array as far as i know
>>
>>54655142
I know it's not a function pointer sweetie, that's why I'm calling you dense.
Function pointers are ONE EXEMPLE of a cast that is undefined behavior.

I'm telling you that what you're doing, which is int* to (int(*)[][]), not function pointers, is probably undefined behavior too under a strict interpretation of the standard.
>>
I'm building a visualizer for fourier transformations in C++ and writing the math parts is killing me.
Can anybody recommend me a good scientific math lib? Cerns ROOT? Something from Boost?
>>
>>54655078
I get what you're saying. But this Item base class is really only for things the Player can "use" when an input is given. Like a player clicks the mouse and it calls use() on whatever the current wielded "Item" is, that's it. Class Item just has a virtual function use(), that's pretty much it. This is why I asked the original question, I didn't know what to call this category of things.
>>
>>54655178
>Function pointers are ONE EXEMPLE of a cast that is undefined behavior.
it's irrelevant, i'm only casting to a data type pointer, not a function pointer, function pointers are the only exception

void* are aligned like chars, it's save to cast form it, otherwise malloc wouldn't work
>>
>>54655088
Can't you just call an input Dialog Box somehow?

For example(not Python):
input = await this.ShowInputAsync("Title", "What is your response?");
>>
File: 3jEmew5.png (6KB, 403x261px) Image search: [Google] [Yandex] [Bing]
3jEmew5.png
6KB, 403x261px
>>54655212
>>
>>54655204
>function pointers are the only exception
Not so.

>void* are aligned like chars, it's save to cast form it, otherwise malloc wouldn't work
Wrong; memory returned by malloc is aligned to largest possible required alignment, which is generally the word size (64bit on a modern CPU).
char is aligned to 1 byte (exactly 8bit on a modern CPU).
>>
>>54655178
>which is int* to (int(*)[][]), not function pointers, is probably undefined behavior too under a strict interpretation of the standard.
It's not.
And it's void * to int (*)[][]
>>
File: 1456014633597.png (60KB, 799x586px) Image search: [Google] [Yandex] [Bing]
1456014633597.png
60KB, 799x586px
>>54655004
i'm not reading through 7000 lines of assembly but it compiles to exactly the same number of lines (7034) with x86 gcc 5.3 -O3

#include <iostream>
#include <stdlib.h>
using namespace std;
void foo(int m, int n) {
int *x = (int (*)) malloc(sizeof(int[m][n]));
x[0] = 0;
x[1] = 1;
x[2] = 2;
x[3] = 3;
x[4 + 0] = 4;
cout << *(x + 0) << endl;
cout << *(x + 1) << endl;
cout << *(x + 2) << endl;
cout << *(x + 3) << endl;
cout << *(x + 4) << endl;
}


#include <iostream>
#include <stdlib.h>
using namespace std;
void foo(int m, int n) {
int (*x)[m][n] = (int (*)[m][n]) malloc(sizeof(int[m][n]));
*x[0][0] = 0;
*x[0][1] = 1;
*x[0][2] = 2;
*x[0][3] = 3;
*x[1][0] = 4;
cout << **(*x + 0) << endl;
cout << **(*x + 1) << endl;
cout << **(*x + 2) << endl;
cout << **(*x + 3) << endl;
cout << **(*x + 4) << endl;
}


gcc.godbolt.org
>>
>>54655249
>And it's void * to int (*)[][]
It's a cast from void* to (int(*)[][]), but the void* pointer is pointing to an int[m*n], not an int[m][n], that's why I'm (incorrectly) saying int* to int(*)[][]
>>
>>54653946
variable length arrays are defined with C99, check which ever flag you need for gcc to enable them
>>
>>54655297
>C99
Useless crap.
C89 is the only true C.
>>
>>54655284
the void* only points to an allocated block of memory of the size that you called malloc with, it doesn't point to any specific type
>>
>>54655268
Well you are accessing and setting the array elements with values known at compile-time, so it's probably optimized and run the same way.
>>
>>54654981
not really, you also need a multiplication operator for 2d arrays
>>
>>54655268
Because you're using constants, compiler probably constant folded everything away.

On the phone right now so can't be bothered to type out shit but compare two functions like this:
int get(int m, int n, int (*a)[n][m], int x, int y)
return element at x,y

and another with 1D array.
>>
>>54655101
you're allowed to cast from void* to any object pointer
>>
>>54655345
any real code would be subject to the same types of optimizations, there is no advantage of using the x[i * m + j * n] syntax over x[i][j]
>>
>>54655313
>C89
>no mixed declarations and assignments
>no mixed declarations and code
>no variable length arrays
>>
>>54655284
objects returned by malloc does not have a type.
>>
>>54653610
>posting the homosexual anime image

Kill yourself.
>>
>>54655370
>implying VLAs are good thing
>>
>>54655381
hime isn't gay
>>
>>54655177

Neither does malloc really. With malloc, you get a block of memory that you can index like a 1D array, but C and C++ both won't let you subscript an arbitrary pointer with multiple subscripts in the p[x][y] fashion because it doesn't know the dimensions. But you can easily transform any 2D subscripting into a 1D subscript if you have the length stored off somewhere. The new operator will just give you the same block of memory the malloc will.
>>
>>54655198
>I'm building a visualizer for fourier transformations in C++ and writing the math parts is killing me.
You never write FFT yourself, only idiots do that. That's like implementing your own encryption, you just don't do that. Use FFTW (http://www.fftw.org) instead. It's very simple to use and has all kinds of possibilities to get close to optimal code.

>Can anybody recommend me a good scientific math lib?
Depends on what you need. Linear algebra? Maybe Eigen. If you want something complete in one package you may want to use Python + Numpy + Scipy + Matplotlib instead.

The ROOT framework is a pain in the ass to use imo. In our department everybody needs to work with it as the experiment we are working on uses *.root files for data. Basically, the first and only thing anybody does with the ROOT framework is converting those files into something that is not horrible to work with.

But well yeah, if you have masochistic tendencies, like barren looking plots and whatnot then go with ROOT. At least you can say it's a pretty complete framework for math (particularly statistics).
>>
>>54655368
No it wouldn't, real code would most likely have x and y as variables which means a full set of address calculations.
>>
>>54655392
no but the picture is
>>
>>54655368
No. You can't make the same strong assumptions about what your program is trying to access if your variables are dynamic. Currently, your code is stored similarly because C and C++ align multi-dimensional arrays. To top it off though, Your cout probably compiles similarly.

The difference when you use dynamic variables, is that *x[1][0] (with something other than 0 at the end) will need a multiplication. With a 0 there, you need to load 1 variable before jumping the same as if you were using a 1d array
>>
>>54655399
You can easily make dynamically allocated arrays with subscripts by doing something like this where ptr->cube is a 3 star pointer.
    unsigned i, j; /* make 3D cube */
ptr->cube = malloc(sizeof(unsigned char **) * x);
for (i = 0; i < x; i++)
ptr->cube[i] = malloc(sizeof(unsigned char *) * y);
for (i = 0; i < x; i++)
for (j = 0; j < y; j++)
ptr->cube[i][j] = malloc(sizeof(unsigned char) * z);
>>
>>54655464
Anyone writes such code should be shot or sterilized at least
>>
>>54655335
It's my understanding that the pointed-to obeject does have a type, and here that type is going to be int[].
The standard says that it is undefined behavior if "An object is assigned to an inexactly overlapping object or to an exactly overlapping
object with incompatible type (6.5.16.1).", and I'm not seeing where it defines int[] and int[][] as having compatible types.

If the standard does not explicitely allow it, then it is by definition undefined behavior.
>>
>>54655464
Not him, or anyone arguing against that, but I sincerely hope no one fragments their free memory likes this
>>
>>54655399
int (*x)[m][n] = (int (*)[m][n]) malloc(sizeof(int[m][n]));
return *x[i][j];
>>
>>54655491
>fragments
It's all continuous memory, you dumb shit, you think your system is that busy?
>>
>>54655399
>Neither does malloc really
But you can do anything with the resulting memory block, like assign a pointer to a two dimensional array to the malloc return and index the continuous space as a multi-dimensional array. It's C after all. shit is fast and loose; that's why I love it.
>>
>>54655487
in C at least (which would 99% carry over to C++) there is no particular type, you can pass a void pointer around from malloc and then cast from it, the compiler doesn't have to know the type
>>
>>54655504
that is 3 dereference per access ``dumb shit''.
>>
>>54655504
dumbass

at the very least it creates a lot of overhead at initialization and deallocation
>>
>>54655504
You mean contiguous

And there isn't a guarantee that mallocing like that would make it contiguous, or would make it contiguous in a way that it's as easy to access as a 1d malloc'd array
>>
>>54655491
java programmers do :>)
>>
>>54655402
>Use FFTW (http://www.fftw.org)
This looks promising, thanks.
>>
>>54655464

I really hope whatever program your doing that in doesn't require a large amount of performance. You're literally thrashing the cpu cache.
>>
>>54655518
Oh yeah on a second reading I think you're right, there's no int[] type at all anywhere.
I'm full of shit, my bad.
>>
>>54655598
Still faster than interpreted tho~
>>
>>54655487
>It's my understanding that the pointed-to obeject does have a type,
Section 6.5 Expressions:

"The effective type of an object for an access to its stored value is the declared type of the object , if any.87)"

"87) Allocated objects have no declared type."

'Allocated objects' means objects returned from malloc (if you look at the definition of allocation and deallocation under the library section).
>>
>>54655464
You are probably better of mallocing everything in one go instead.

>>54655504
No, it's not. Malloc does not only give you a bit of memory, malloc also saves some kind of header somewhere (depends on implementation where and what exactly is in that header). If possible you should always use as few mallocs as possible.

On the other hand, it probably won't matter measurably.

Still, I prefer to do three dimensional arrays simply by defining some struct like
typedef struct {
double *d;
size_t *size;
} array_t;


and then define a function like
double *get_element ( array_t *A, size_t i, size_t j , … )
{
return &A [ i * A->size[0] * A->size[1] * … + j * A->size[1] * A->size[2] * … + … ]
}

etc. May not look as clean as just using A[i][j][…], but that gives you the additional possibility to check every array call, because when working with three or even more dimensional arrays, you are very likely to run into seg faults at some point. Then it is always nice to be able to give a proper error message. Or sometimes to even just ignore those or whatever is suitable.
>>
>>54655697
Thanks, much appreciated.
>>
>>54655361
dunno how to get that shit to compile

int get(int x[8][8], int i, int j) {
return x[i][j];
}


        movsx   rsi, esi
movsx rdx, edx
sal rsi, 5
.LVL1:
add rdi, rsi
.LVL2:
mov eax, DWORD PTR [rdi+rdx*4]


int get(int x[], int m, int n, int i, int j) {
return x[i*m + j*n];
}


        imul    ecx, esi
.LVL1:
imul r8d, edx
.LVL2:
add ecx, r8d
movsx rcx, ecx
mov eax, DWORD PTR [rdi+rcx*4]
>>
>>54655705
Ruby, that looks fucking horrible pls don't write C anymore, thanks/.
>>
>>54655705
>cache misses won't matter measurably
just stop programming
>>
I have been working in Windows environment for a few years now developing .Net apps but I finnaly changed to Ubuntu and I love.

Only problem is that I cannot flee from Visual Studio that shit is just so good so I run it inside a VM.

Mono is shit.

Now I'm interested to learn different languages.
For example C++ because Qt-creator and I want to add more functions to Clementine. Just basically implement some stuff from Jet Audio.

Also I'm into Java, now that Xamarians merged into the armpit of Microsoft I have the Forms for free so I can work with C#. But I want to learn Java to build "native written" apps for Android. I know I can do this with C++ too.

Which language should I choose? Java is basically C# so it will be familiar.
>>
>>54655736
Needs C99.
And the latter isn't even correct, you don't multiply both dimensions.
>>
>>54655762
java and then C++, both are useful for android, you can use them together with JNI
>>
>/dpt/ - C array general
>>
>>54655762
Somewhat related, but if you're looking for a good IDE, Jetbrains >>> VS imo.
>>
>>54655784
nah, it won't need C99. Or do you mean something else than VLA?
>>
>>54655784
>needs C99
ok i guess i'd just have to pass a compiler flag but i cba tbqh

>you don't multiply both dimensions

int get(int x[], int m, int n, int i, int j) {
return x[i*m + j];
}


        imul    esi, ecx
.LVL1:
add r8d, esi
.LVL2:
movsx rsi, r8d
mov eax, DWORD PTR [rdi+rsi*4]
>>
>>54655736
>movsx rsi, esi
>movsx rdx, edx
What the fuck is your compiler doing.
Just doing the whole operation with the 32bit variables would have been less expensive than the weird 32->64->32 conversion.
>>
>>54655797
>Jetbrains
Those who made R#? No way.
>>
>>54655811
Variably declared array types is also C99.
>>
>>54655762

You've already bought into the corporate mold so java should be fine it's a more boiler plate filled tedious predecessor to c#.

C++ or C will most likely be a giant adjustment and odds are if your work is mainly .net apps now you're probably not looking to move to a field that will require c or c++ (Game Dev, Embedded devices, Ultra high performance applications, and general systems level work like drivers.)
>>
>>54655823
yes, I know. But that is not VLA
>>
/dpt/-chan, daisuki~

Ask your much beloved programming literate anything (IAMA).

>>54655736
int get(int n, int i, int j, int x[][n]) {
return x[i][j];
}


        movsx   rsi, esi
movsx rdi, edi
movsx rdx, edx
sal rsi, 2
lea rax, [rcx+rdx*4]
imul rsi, rdi
mov eax, DWORD PTR [rax+rsi]
ret
>>
>>54655751
>He uses some convention that I don't use boohoo

>>54655758
For most cases, it really won't though.
>>
>>54655834
if i changed [8][8] to [m][n] (to make it consistent with the dynamic meme) it'd be VLA wouldn't it?
>>
>>54655817
Needs to sign extend in case they are negative.
It's why you should never use (32 bit) ints as array indices on 64 bit platforms because you pay all those extra sign extend instructions.
>>
>>54655818
Regardless of whatever other things they've come up with, their IDEs are the best out there
>>
>>54655854
oh yeah i use unsigned in real code

nice catch
>>
>>54655834
Yes, that's why I said variably declared type, not vlas.
>>
>>54655851
Nope, I doubt you can pass VLAs. You can cast them thought
>>
>>54655854
No need to sign extend if you do the SAL, ADD and MOV with ESI and EDX directly, instead of sextending into RSI and RDX.

It'll cost a couple extra prefix bytes, but you more than win that back by not doing the two sign extend.

Or am I missing something obvious?
>>
>>54655851
It should be int (*a)[m][n]
>>
>>54655900
The address calculation has to be 64 bit arithmetic.
>>
>>54655908
not the same semantics.
>>
>>54655981
Oh yeah overflow, I'm a retard. Thanks.
>>
>>54655984
we wanted to compare >>54654814 vs emulating a 2d array with a dynamic 1d array
>>
>>54655212

It turns out there is a tkinter module called simpledialog that does exactly that, thanks.
>>
>>54655984
Yes, obviously since we've been talking about dynamically allocated 2D arrays, not VLAs.
>>
>>54656021
So many times help on /dpt/ comes by just finding the term to google.
>>
>>54656024
vla has nothing to do with procedure arguments, retard.
>>
>>54655993
rygorous did a nice writeup recently about this:
https://gist.github.com/rygorous/e0f055bfb74e3d5f0af20690759de5a7
>>
>>54656010
then it should be

(*p)[x] vs (*p)[x][y], not *p vs (*p)[x][y]
>>
>>54656102
how would you malloc the 2d equivalent (one extra dimension) of *p so that you can use it like p[i][j]
>>
/dpt/ would you use this programming language if you could?

>a statically typed async scripting language with C-family syntax and both object-oriented and functional features
>code files are rich text rather than plain text, and formatting is used for various features
>threads can be created using the bifurcate code word which divides following local statements based on font color.
>all methods require something called a "mortal" as the first argument. The method runs on the "death" of that mortal
>loops also depend on a mortal, running continuously until that mortal is dies
>the source code of the language is actually translated from eldritch tomes and as a result the language specializes in automating literal black magic, such as cursing people, summoning demons, rigging people's computers to literally explode
>the aforementioned mortals are actually real-world creatures or objects with an actual lifespan, meaning it may be necessary to automate sacrifice externally to get code to run at a standard pace
>>
>>54656129
>code files are rich text rather than plain text
Stop there.
>>
>>54656123
not sure to get it. do you mean this ?

int *p = sizeof(int[x][y]);
>>
>>54656129
I was sort of interested and then what the fuck.
>>
>>54656141
no i mean so you can use p[i][j] instead of p[i*x + y]
>>
>>54656141
>>54656123

forgot malloc

int *p = malloc( sizeof( int[x][y] ) );
>>
>>54656129
Fuck off, Sollux.
>>
>>54656088
Yes it has.

void f(int m, int n, int a[m][n])

here a is an auto adjusted pointer to a vla.
>>
>>54656129
how fast is it tho?
>>
>>54656153
>p[i*x + y]
p[i*x + j
>>
>>54656164
when running as fast as any scripting language but since every method only executes upon something dying, it's very slow relatively speaking
>>
>>54656102
The point of (*p)[i][j] is to be able to have both dimensions variable, and a dynamically allocated to a contiguous block of memory and being able to use nested bracked syntax instead of manual linear address.
So it IS supposed to be double indirection vs single, and we've trying to tell some retard that the manual linear address is more efficient in that case.
>>
>>54656203
Delete that shit and use [].
>>
>>54656203
you fucker
>>
>>54656213
when dimensions aren't variable like int[8][8] it's not extra overhead though
>>
 include <stdio.h>

int main(int *l) {
int i,j,c;
printf("enter max number: ");
scanf("%d",&c);
for(i=1;i<c;i++) {
for(j=1;j<c;j++) {
l[c]=j+1;
if(i%j==0 && j != l[c]) {
printf("%d and %d\n",i,j);
}
if (i==20) {
i=1;
if (j == 20) {
break;
}
}
}
}
}

© 2016 All rights reserved

Getting error. I want to get list of prime numbers. Where is the fault? help me please.
I'm new to this
>>
>>54656203
[spoiler]Use [] for code tags.[/spoiler]
>>
>>54656161
vla is when you are defining an array, you are defining a pointer here. sizeof(a) will return the same size as a pointer.
>>
#include <stdio.h>

int main(int *l) {
int i, j, c;
printf("enter max number: ");
scanf("%d", &c);
for (i = 1; i < c; i++) {
for (j = 1; j < c; j++) {
l[c] = j + 1;
if (i % j == 0 && j != l[c]) {
printf("%d and %d\n", i, j);
}
if (i == 20) {
i = 1;
if (j == 20) {
break;
}
}
}
}
}


At least indent your shit, faggot. Clang-format literally takes 5 seconds.
>>
>there are people that use VLAs
even later C standards ditched it, most compilers do not support it or at least require compile flag to enable them
>>
>>54656282
>most compilers do not support it
-- sent from my RHEL 4
>>
>>54656267
I first used 20 as my max number
>>
What exactly is a VLA?
Does creating a stack-allocated array using a variable as a subscript count as a VLA?
I'm not resizing it during the function call.
>>
>>54656301
It's a meme that someone thought would be a good idea when C is a language of explicitness
>>
>>54656241
that is not a valid main and you are writing on command line arguments.
>>
>>54656301
>What exactly is a VLA?
An array whose length is not known at compile time.

>Does creating a stack-allocated array using a variable as a subscript count as a VLA?
Yes, unless the variable is actually a C++ constexpr, but C++ doesn't officially have VLAs.
>>
>>54656267
int main(int *l) {
..
l[c] = j + 1;
..
}
>>
File: umaruic.webm (1MB, 640x360px) Image search: [Google] [Yandex] [Bing]
umaruic.webm
1MB, 640x360px
>>54656213
int get_pointer_int (int n, int i, int j, int x[][n]) {
return x[i][j];
}

int get_pointer_array (int n, int i, int j, int (*x)[][n]) {
return (*x)[i][j];
}

=== x86 ===

get_pointer_int:
mov eax, DWORD PTR [esp+8]
mov ecx, DWORD PTR [esp+12]
sal eax, 2
imul eax, DWORD PTR [esp+4]
lea edx, [0+ecx*4]
add edx, DWORD PTR [esp+16]
mov eax, DWORD PTR [edx+eax]
ret

get_pointer_array:
mov eax, DWORD PTR [esp+4]
mov edx, DWORD PTR [esp+16]
and eax, 1073741823
imul eax, DWORD PTR [esp+8]
add eax, DWORD PTR [esp+12]
mov eax, DWORD PTR [edx+eax*4]
ret


=== x64 ===

get_pointer_int:
movsx rsi, esi
movsx rdi, edi
movsx rdx, edx
sal rsi, 2
lea rax, [rcx+rdx*4]
imul rsi, rdi
mov eax, DWORD PTR [rax+rsi]
ret

get_pointer_array:
movsx rax, edi
movsx rsi, esi
movsx rdx, edx
sal rax, 2
shr rax, 2
mov rdi, rax
imul rdi, rsi
add rdi, rdx
mov eax, DWORD PTR [rcx+rdi*4]
ret
>>
>>54656301
it is a mistake.
>>
>>54656316
So the official line on C11 is to use malloc if your array size isn't a constant?
>>
>>54656341
>C11
hipster detected
>>
>>54656251
Yes, I said, it's a pointer to a VLA.
>>
>>54656341
use a big enough buffer. use malloc if size is too big
>>
>>54656341
VLAs are optional in C11, if your compiler supports them it's perfectly okay.

Otherwise you can always use alloca if you're a horrible person and you really want a dynamic stack array.
>>
New thread: >>54656358
>>
>>54656324
that's the problem?
>>
>>54656366
>>54656366
>>54656366
NEW
>>
>>54656361
"it's perfectly OK" as in "it's perfectly OK to suck dicks" though
>>
>>54656358
>>54656358
>>54656358
>>54656358
>>54656358
>>
>>54656373
>>54656371
>>54656367
A U T I S M
U
T
I
S
M
>>
>>54656129
top kek
>>
File: swaglordHammer.jpg (69KB, 867x1024px) Image search: [Google] [Yandex] [Bing]
swaglordHammer.jpg
69KB, 867x1024px
>>54656367
>>54656371
>>54656373
NICE. FUCKING. JOB.
You fags should all get b& for trying so hard to spam your meme threads.
>>
>>54656386
Can't argue with that, but to be fair the stack is a nice and cozy cache-friendly place, so it can make sense to use VLAs in some cases.
>>
>>54656397
the ONLY reason i'm posting threads at all right now is because of the trap poster, it's ALL the trap poster's fault

>>54656414
MOOOOOOOOOOOODS BAN THIS TARD FOR FUCK'S SAKE

REAL THREAD; IT WAS FIRST

>>54656358
>>54656358
>>54656358
>>
>>54656366
>>54656366
REAL THREAD
>>
>>54656199
This is more a flaw of infrastructure. We do not say a computer is slow because one has to feed it electricity.

A sufficiently developed country will be able to provide the necessary deaths.
>>
>>54656428
Calm down autismo.

New hime thread in 307 posts!
>>
File: 1361752574642.png (170KB, 519x424px) Image search: [Google] [Yandex] [Bing]
1361752574642.png
170KB, 519x424px
>>54656414
>>54656428
>>54656429
You've got to be kidding me.
>>
the trap thread got deleted so i deleted mine voluntarily, the dat boi thread is cool

>>54656366
>>
>>54656428
Oh for fucks sake your autism about "muh trapfags" is incredible. Stop shitting up my /dpt/.
>>
>>54656451
Cheers pal, I was going to delete mine too, but noticed you already deleted yours
>>
>>54656429
Mods seem to have chosen.
>>
>>54656422
Problem is there's no way to detect or recover from overflowing the stack, so you have to have a reasonable cap on the array size, and if you have that you might as well just make it statically sized to that cap from the beginning.
>>
>>54655705
>malloc also saves some kind of header somewhere (depends on implementation where and what exactly is in that header).
Most intelligent mallocs will use arenas so there is one small header per 64KB-4MB or so. malloc ask for entire chunks and then spreads it around.

>>54656091
This is why for indexes you should always be using size_t or some other unsigned pointer size type.
>>
>>54656500
The only case I can think of is if you have several VLAs, each of which can grow significantly, but not at the same time.

So you can't preallocate all the arrays at their full capacity without overflowing, but capping the total size of the combined VLAs would work.

#ProblemsThatWillNeverOccur
>>
>>54656563
if you use multiple mallocs for the array then you can't (safely) zero it with a single memset call, that was the original issue that sparked this entire debate
>>
>>54656689
Why do you need to zero it if you're gonna fill it up completely?
>>
>>54656689
Yeah, I know. Just "the more you know". I figured it was more about malloc trying to allocate memory in proximity to the other used blocks.
>>
Whats the best way to learn a language?
>>
>>54658180
learn the syntax and basic concepts

https://docs.oracle.com/javase/tutorial/

and then do a mid-sized project of something you're interested in
>>
>>54658220
What about C
>>
>>54658381
C is ok and a lot better than most of the alternatives /g/ would suggest. personally i'd recommend starting with java and then moving on to C++ and then C will come naturally. C++ is like a more advanced C and java is like a simplified C++.
>>
>>54658457
>i'd recommend starting with java
opinion discarded
>>
>>54658546
whats the new meme starting language now?
Thread replies: 341
Thread images: 18
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y / ] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK