[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: 255
Thread images: 17

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

What are you working on, /g/?
>>
first for crossdressing haskllers
>>
ACTUAL NEW THREAD:

>>51953865
>>51953865
>>
>>51953918
fuck off
>>
I remember when /dpt/ used to get me excited and motivate me to program. Now I just come here to take a shit.
>>
Threadly reminder that there is nothing wrong with singly-linked stack implementations.
void stack_push(stack_t *stk, int data)
{
frame_t *frame = (frame_t *) malloc(sizeof(frame_t));
frame->data = data;
frame->next = stk->head;
stk->head = frame;
stk->size += 1;
}

int stack_pop(stack_t *stk)
{
if (stk->head == NULL)
printf("Stack empty.\n");
frame_t *frame = stk->head;
int data = frame->data;
stk->head = frame->next;
stk->size -= 1;
free(frame);
return data;
}
>>
I'm partial to cute trap thread
>>
#define my_macro(X) (X) * (X)

int main() {
void *macro = my_macro;
int x = 5;
macro(5)
}


why doesn't this work?
>>
>>51953972
i like this meme
>>
>>51953972
>singly-linked stack
Why would we need to know the previous of a stack? Once it's at the top, the previous is null.
>>
>>51954011
what the fuck
I only posted this in one thread lmao
did you copy it or is this me
>>
>>51954011
pass it to cpp and see what's the output
>>
>>51954040
The previous links to the previous link
when popping, you set stk->head to the stk->head->next.
>>
>>51954062
this is C, not C++
>>
>>51953972
horribly inefficient
>>
>>51953972
Well, except your null pointer exception.
>>
>>51954079
cpp is the C preprocessor, not the C++ compiler
>>
>>51954096
What's the correct way to handle those? bypass the free operation and simply return 0?
>>
>>51954058
a macro doesn't have an address
>>
>>51954114
I'd say to bypass everything and return a special value. 0 isn't a special value if it's the data, as you could put 0 on the stack.

You could pop the data into an argument pointer and use the return value as an error indicator.
>>
>>51954114
have it return true/false, pass in a reference to collect popped value. Returning a valid value on success or a valid value on failure could put code using this implementation in an undefined state.
>>
Thinking of writing a program that grabs code from posts in the /dpt/ and runs it
or something like that
for example, if I wrote this

a = 5
print('{0}'.format(a)) # python3 is shit

it would run it in my term, showing the post number too

I want to make it do something interesting though, idk

Perhaps I would make it so that you gave it the post number instead so people can't wipe my hard drive

I want to make something out of posts in /dpt/ though, where each post affects the program in some way
I think it would be fun, but I'm having a hard time coming up with an idea on what it would do
>>
>>51954195
>>51954223
Maybe I could just have it return an enum value STACK_EMPTY or something?
>>
>>51954226
Have it analyze word frequency as well as the frequency of words in proximity to each other.

Then have it start posting.
>>
>>51954274
so just a markov chain

I couldn't do posting because captcha, but I could post the output

I'll get started on it
>>
>>51954250
as long as you separate identifying the result and the result itself, that would suffice, but it's a bit more overhead than necessary.
>>
Why are people still posting in the other thread?
Don't they realize mods always delete the newest one?
>>
>>51954296
you can offload the captcha solving to amazon turks
>>
>>51954332
>don't know how things work around here
>don't like anime
Hmm...
>>
>>51954332
Why support the trap thread?
If you dont approve dont post in it. Its really simple.
>>
File: haskell_logo1.png (30KB, 647x599px) Image search: [Google] [Yandex] [Bing]
haskell_logo1.png
30KB, 647x599px
I am trying to learn Haskell, how would I create a function that takes a list like [1,2,1] and creates the list [1,1+2, 2, 2+1, 1]?
>>
>>51954404
Oh and it should work for arbitrary lenght of lists
>>
>>51954404
>>51954427
Break it up into sub-problems. For example:
1. How do you generate the list [1+2, 2+1] from [1, 2, 1]?
2. How do you merge those two lists to get [1, 1+2, 2, 2+1, 1]?
>>
Do people write real software in haskell or is it just a toy language for autists?
>>
>>51954459
And then you can be super 1337 with your composition.
-- insert your code here
generate :: Num a => [a] -> [a]
merge :: [a] -> [a] -> [a]

-- composed
generateAndMerge :: Num a => [a] -> [a]
generateAndMerge = merge <*> generate


>>51954504
https://wiki.haskell.org/Haskell_in_industry
>>
>>51954504
if you have to ask...
>>
void *macro = my_macro;


How the macros are bad meme began
>>
File: kp.png (130KB, 1836x834px) Image search: [Google] [Yandex] [Bing]
kp.png
130KB, 1836x834px
r8 my solution f︂︂a︂m.

function eqSumPowdig(hMax, exp) {
var i,
j,
sum,
digits = [],
answer = [];

for(i = 2; i <= hMax; i++) {
sum = 0;
digits = i.toString().split('');
for(j = 0; j < digits.length; j++) {
sum += Math.pow(parseInt(digits[j]), exp);
}

if(i === sum) {
answer.push(i);
}
}

return answer;
}
>>
>>51954504
It's entire purpose was just to be an academic/toy language for autists but there are some real world applications written in haskell, yeah.

>>51954522
>IMVU
nice
>>
Why the fuck can't I have an unused function in my Go program? I'll be using it in just a few minutes Jesus.
>>
>>51954404
>take first two elements
>add together
>cons 1st element with the results
>recurse on the rest of the elements with the second elements cons to it.
>>
>>51954504
A bit, like some finance firm has it and some antispam software but no mostly a language for autists and academics. And dont confuse that it isnt used for software that the language is garbage, many discoveries in comp sci is from a bunch of academics using haskell
>>
>>51954522
>https://wiki.haskell.org/Haskell_in_industry
>weedreporter
ayy lmao
>>
Why the fuck can't I have an unused variable in my Go program? I'll be using it in just a few minutes Jesus.
>>
>>51954549
>using go
>>
>>51954574
go is shit
>>
>>51954574
use a sane language that doesn't give a shit like C
>>
>>51954404
I'm not sure if I understand you correctly. This works for your example though.
f :: [Int] -> [Int]
f (a : b : cs) = a : ((a + b) : (f (b:cs)) )
f x = x
>>
Why the fuck can't I have an unused import in my Go program? I'll be using it in just a few minutes Jesus.
>>
>>51954549
>>51954574
2 minutes later and you haven't honored your half of the deal. the clock is ticking
>>
>>51954549
Holy shit, lmao. I'm glad I decided not to learn Go
>>
>>51954584
f (a : b : cs) = a : (a + b) : f (b:cs)
>>
>>51954584
f (a : bs@(b : cs)) = a : (a + b) : f bs
f x = x
>>
>>51954578
>>51954579
>>51954582
>>51954596
Go is nice for networking. Enough to compensate for its general shittyness.
>>
haskell truly is an arcane meme

>>51954627
a lot of other languages have just as nice networking
>>
>>51954637
Neither C or Python do

Hell no does Java; too verbose
>>
>>51954664
Congratulations, you argued that 3 other languages don't. Good work!
>>
>>51954702
So what language does?
>>
>>51954584
Seems to work perfectly thanks, Haskell is pretty hard to learn desu. just needed something that generates the denominators for the Farey Sequence
>>
>>51954664
>networking
>needing anything other than sockets
>>
>>51954709
Python, actually. Ruby as well.
>>
>>51954759
Data serialization, encoding, compression, hashing, encryption, threading...
>>
>>51954803
>having to type .encode('utf-8') after every string
>>
Refactoring my code yet again since I've changed how thread switching works. Fun!
>>
>>51954847
>what is ssl
>>
With markov chains of text, is each state a word, and the chain is of all of the known words, for example?
>>
>>51953857
Newfag here
Recommend me 1 book on Java that
-Doesn't shill any specific IDE, encourages to use the terminal instead
-Has plenty of self tests/exercises
-Not written by a currynigger

I only know python
>>
>>51955245

> -Doesn't shill any specific IDE, encourages to use the terminal instead

Use a IDE or you will die.
>>
Clion is actually a really nice IDE.
>>
>>51955287
I will, but I'd really like to have my own choice
>>
>>51955302
>get it for free because I'm a student
>get it all setup
>never use it again
I feel kinda bad, but at the same time using a text editor and compiling shit yourself is more satisfying
>>
>>51955503
>get it for free because I'm a student
dropped

How could anyone in their write mine develop software with a closed-source IDE is beyond me.
>>
>>51955644
why is this thread here when the other 1 is better
>>
>>51955658
why are you asking me
>>
>>51955644
>write
>>
>>51955644

I'm sure you can imagine using closed source software.
>>
>>51953857
Swift calculator
>>
>>51955743
Holy shit, I was listening to someone talk when typing that post
>>write mine
Jesus christ lmao

>>51955761
Not for an IDE, though. I've used vim since I started programming and I've always loved knowing exactly what I'm doing. I think I just dislike IDEs in general, although I could really use tooltips on hover, which I don't think there could be a plugin for
>>
>>51955804
>Not for an IDE, though.

I don't see how it's distinctly different than any other closed source software.

Do you think it's sending your leet source to JetBrains or something?
>>
>>51955904
No, I just don't trust it not injecting /something/ into my code.
JetBrains doesn't care about my toy programs lol
But I honestly just prefer writing makefiles and having control over everything and not having my project bound to some IDE
I've seen a few github repos where the installation is "open this project in QtCreator then click Build and Run" and it's just autismo
>>
JUST CRUD MY SHIT UP

Flask + SQLAlcgemy Rocks!

Also, you like my IDs? How do you generate your IDs?
#justwebdevthings
>>
>>51955935

Fair enough, I just think they provide some tools which increase productivity.
>>
>>51955963
Your fortune: codemonkey
>>
>>51956004
Yup.
Did that term come from monkey-patching? Because besides writing SQl I just patched/formed my own Flask

I also have to deploy and maintain so DevOp :)
>>
>>51956040
>>>/g/wdg/
this is the programming thread
>>
>>51955963
my ids are hashes of registration time and first name with "cuck-" appended at the front for male and "bulldyke-" for female
>>
File: welp fuck.gif (2MB, 398x261px) Image search: [Google] [Yandex] [Bing]
welp fuck.gif
2MB, 398x261px
>Tried to make a hangman game in python while waiting for my plane
>You can't just enter in one letter as input in python

Granted I had a couple rum and gingers before I sat down to make it but is that shit real?

Can you really not just enter one letter as input, do you really need gletch or whatever the fuck?
>>
>>51956072
Are you retarded?
>>
>>51956106
Are you stupid?
>>> cuck = input(":")
:a
>>> print(cuck)
a
>>
>>51956117
>flask
>SQL
>DevOp
sounds webdev to me
>>
>>51956088
what if someone registered at the same time with the same gender?
>>
>>51956158
well then they should include their RACE as well, if you get what I mean.

what I mean is, the RACE will need to be an additional CONDITION. a CONDITION to consider is RACE.
>>
C++ bros i need help again, I need to understand what happens here.

So lets say i create 3 variables and add them up inside the
print statement. According to logic, every value must go into
memory but what happens to the value that is printed out after
it is evaluated inside the print statement? Where does the value "20"
go into in the memory?

int threenumbers()
{
int g = 6;
int d = 4;
int p = 10;
std::cout << "Sum is " << g + d + p << std::endl;
return 0;
}
>>
>>51956158
>>51956195
why doesn't every registrant get a unique randomly generated hash?
>>
>>51956222
they should, i agree
>>
I want to get into machine learning, specifically I would like to make an extension that can try and solve captchas. It doesn't have to be amazing but the whole area is very interesting to me.

Any good places to start?
>>
>>51956222
how about

hash of current unix time + hash of randomly generated numbers

that cool enough for collisions?
>>
>>51956259
plus the registrants information for salt
>>
>>51956270
ok, but that would be too long no?
how do we clip/trim and combine from the three generators?
>>
>>51956283
just throw them into a sha1 hash, nobody cares.
>>
>>51955963
>How do you generate your IDs?
Synchronized monotonically increasing ints? You have to get into some high-performance shit before they stop being a perfectly reasonable primary key.
>>
>>51956072
try harder
>>
>>51954226
I don't like this
why does Guido think that looks better than
print '%d' % a
>>
>>51956207
that behavior has to do with your architecture and not c++ but typically it would be left in a memory region called the stack, and can be overwritten later by a future function call.
>>
>>51954627
Explain how to upload multiple files using one POST request with Go.
>>
>>51956300
at least sha128
>>
>>51954899
>Not writing a class that will handle that for you
>>
>>51953857
non-trap thread: >>51953865
>>
>>51956436
>i don't like anime and this is my first day on 4chan
the post
>>
>>51956361
Is there a way i can read that value back out from the memory? After it has been evaluated in the print statement of course.
>>
>>51954565
>weedreporter
Maybe I should take a look at Haskell after all.
>>
>>51956472
n o
have you considered doing
sum = a + b + c
std::cout << sum
>>
>>51956254
Pattern Recognition and Machine Learning, Bishop
>>
>>51956158
because it's a synchronized process. Only one registration is processed at once and time is not cached before being blocked.
>>
>>51956452
>i'm a huge faggot please rape my face
>>
hey people, can you please help me with this?
https://jsfiddle.net/m66tpc4c/
I can't get this working in chrome, and I don't get why it doesn't worl
>>
I scrapped some html for some lewd stories - should I post code
>>
>>51956626
this is the programming thread
>>
>>51956626
txtarea doesn't have a closing div. Thank me later.
>>
>>51956703
>>51956717
did you guys even open the link in chrome?
>>
>>51956706
performance matters a lot, especially for things like games and especially for mobile games. i'm gonna make a taylor series approximation for a function and it will make a very real difference because i profiled it and it alone is taking up a very large percentage of CPU time. trigonometric functions aren't cheap
>>
>>51956766
I'm talking about optimization for the sake of optimization, not actually profiled bottlenecks in cpu intensive applications (which are a really small percentage of modern software).
>>
>>51956800
well for a performance-sensitive application you can still afford a bit of time to clean up the style of the function, remove pointless computations, arrange the variables and code to be more likely to fit cache access patterns
>>
>>51956800
Because they're new, and don't know any better?

I'd rather new programmers overestimate the need for high performance than go completely in the opposite direction and get accustomed to writing absolute dogshit code.
>>
>>51956763
yup.
>>
>>51956829
What about new C programmers who think micromanaging their memory usage = faster code?

like >>51953972
mallocing for every new item in a linked list is slow as fuck
>>
>>51956853
That guy is a troll, not a new programmer.
>>
>tfw tired
>>
>>51956839
you didn't notice anything strange? what version of chrome/ium are you using?
>>
>>51956919
THIS IS NOT THE WEBDEV GENERAL
>>
>>51956829
I wouldn't. I'd rather have readable beautiful code than "but if I add a function call there's overhead" tier autism.
>>
>>51957010
I think you'd be hard pressed to find someone who cares about performance that much but isn't aware of things like inlining. But you're right, as long as they understand things like complexity as well as certain other factors like GC or cache when applicable, even intermediate programmers don't really need to care.
>>
>>51956999
exactly.
nice trips, btw.
>>
>>51957038
thanks
>>
File: crying-baby.jpg (19KB, 438x374px) Image search: [Google] [Yandex] [Bing]
crying-baby.jpg
19KB, 438x374px
>>51956999

>No! You're not a real developer who writes/uses programs like I do!
>>
>>51957055
>>WEBDEV
>>DEV
webdev is development
it's not programming
this i the programming thread
not the development thread
>>
>>51957055
There is literally a general dedicated to webdev.
>>
>tfw tired
>>
I have a stupid question about Github. I want to use the API to check whether there's a new release available, and prompt the user to download it if there is. The actual code works fine, but I need to use an oauth token in the URL for it to work. I generated a token that only has public_repo access, but when I submit it to github, the token gets revoked. Trying to do it without the token gives a 403 forbidden error. Anyone done something like this before?
>>
>>51957055
GET OUTT AHERE G-GGET OUTTA HERE
G-GET OUTTA HERE
>>
>>51957091
You got banned from github.
>>
>>51957078
>>51957080
>>Developer are programmers to a greater or lesser extent.
>>Computer scientists are programmers to a greater or lesser extent.
>>Enterprise software is the domain of the developer.
>>
>>51956800
sometimes every clock cycle matters so writing code in a way which helps your compiler optimize from the start is key.
>>
>>51957118
We noticed that a valid OAuth access token of yours was committed to a public GitHub repository. Publicly disclosing a valid access token would allow other people to interact with GitHub on your behalf, potentially altering data, your contact information, and billing data.

As a precautionary measure, we have revoked the OAuth token. A new token will need to be generated in order to continue using OAuth to authenticate to GitHub. Here are a couple of steps you can do to ensure your account security has not been compromised:

* Review any unauthorized OAuth applications, and remove any you don’t recognize: https://help.github.com/articles/keeping-your-ssh-keys-and-application-access-tokens-safe/#reviewing-your-authorized-applications-oauth
* Review you security log to ensure that no other malicious activity has occured: https://help.github.com/articles/reviewing-your-security-log/

Which is fair enough, but the scope is limited to public, so there's no practical way to do anything interesting with it.
>>
>>51957150
If you're talking about cache optimization, that's less about what the compiler can do and more about how the CPU runs the machine code. The compiler really can't help you at all to utilize the cache better, except potentially by inserting prefetch instructions.
>>
>>51957091
Why not just have a single file in the repo with the version as a line and access the raw via the http url? And if there is an update do the usual cloning via whatever.
I mean, using the API is nice, but this hackaround solution I propose sounds like a lot less effort if that's the only functionality you need.
>>
>>51957150
>In extremely rare cases for particular pplications, every clock cycle matters
Fixed that for you. For 99% of code development times > performance.
>>
>>51957139
this is the programming thread, not the developer thread
a programmer is a type of developer
a webdev is a type of developer
this thread is for the former
>>
File: lol.png (196KB, 1440x900px) Image search: [Google] [Yandex] [Bing]
lol.png
196KB, 1440x900px
>people talking shit about java and using anti java memes to me in facebook and this board
>>
>>51957223
you fucking retard didn't even open the link in chrome
>>
>>51957235
>Cristian was the lower case pro-Java shitposter all along
It's like poetry, sort of.
>>
>>51957240
i saw the code lol

>>51957235
are you still working on that, its been months
>>
>>51957171
i was not referring to anything specific

>>51957186
yes its quite niche, all though probably more common than you think. Real time systems for example.
>>
File: repo.png (58KB, 1223x671px) Image search: [Google] [Yandex] [Bing]
repo.png
58KB, 1223x671px
>>51957249
more like working on and off.
the repo is 26 days old bro.
It's done.

right now I'm thinking over how to code the second part which will contain other stuff like the physics moving strenght or where cancels should go or the inputs.

Also after that I'll make a level editor.

Dunno if working full on the engine to make it so normies could use it or just say fuck this shit and work only for me.

>>51957247
what do you mean?
>>
>>51957294
Really though, the only optimization concerns that affect the design of your entire application from the beginning are cache, and threading. Neither of which can really be attributed to the compiler doing something smart for you.
>>
>>51957316
>github gui client
haha
HAHAHAHAHA
>>
>>51957316
only work for you
i started my game the last time I saw you post this a few months back and finished it a month ago, C and SDL
you seem to be making an actual fighting game though so that's more complicated (mine was just a platformer)
>>
>>51957330
>Tfw I do a game jam with an artist and musician
>Try to teach them how to use the git command line
>It's 4 fucking sentences they have to remember
>The get guis and ask me questions I can't answer
Hnnnng
>>
>>51957330
>hating easy tools
;^)

>>51957353
dunno, it's hard to make progress when you suffer from depression every two weeks or something.
>>
>>51957330
serious question, how does one look at previous commit versions of files and different branches using command line git?
>>
>>51957353
BTW there was a shitty bug that took me two weeks to solve after asking the libgdx irc guys.
>>
>>51953972
Everyone saying this is a troll. Can someone explain to me why?
>>
>>51954011
A macro isn't a function, it's just simple substitution, the preprocessor allows for some syntactic variation, such as enabling the use of parameters as in your example.
So, there is no call and no return, and no increase in cyclomatic complexity because it is an open subroutine.
What you have done is:
#define my_macro(X) (X) * (X)

int main() {
void *macro = (X) * (X);
int x = 5; // Why is this even here?
macro(5)
}
>>
>>51957419
using a linked list for a stack is the most retarded thing and is nearly 100x slower than an array

>>51957436
posted that as a meme, sorry you took the time to reply
>>
>>51957031
it's surprising how many people think that putting inline in a function declaration increases performance
>>
>>51957451
Wouldn't you have to worry about filling up the array?
>>
>>51957493
Are you saying that it does not improve performance, or are you saying that the increase in performance is negligible?
>>
>>51957516
yes, my linked list stack has no possible way to overflow unless you run out of memory
>>
>>51957516
what is realloc
>>
this:
rect(69, 139, 262, 69);
fill(0, 0, 0);
textSize(43);
text("Click Here", 95, 185);
mouseClicked = function(){
noStroke();
fill(247, 243, 168);
ellipse(69, 366, 69, 69);
ellipse(122, 367, 69, 69);
fill(237, 99, 99);
ellipse(95, 187, 69, 69);
fill(247, 243, 168);
rect(60, 191, 69, 176);
stroke(0, 0, 0);
line(97, 170, 96, 152);
};

what is my life?
>>
>>51957548
computationally expensive compared to reallocing every item as needed
>>
>>51957548
But then you're just making stabs in the dark about how big to make the array
>>
void stack_push(stack_t *stk, int data) {
if (stk->size == stk->alloced) {
stk->array = realloc(stk->array, 2 * stk->size);
stk->alloced *= 2;
}
stk->array[stk->size++] = data;
}

int stack_pop(stack_t *stk) {
if (!stk->size) {
printf(stderr, "popping from empty stack\n");
exit(EXIT_FAILURE);
}
return stk->array[stk->size--];
}


it also happens to be way, way faster
>>
>>51957599
your stack doesn't shrink?
0/10
>>
>>51957596
nope, *2 is the optimal, unless all of your heap is consecutive and you can reclaim, then *1.5

>>51957592
lmao

people finish their first semester in cs and think linked lists are for everything
>>
>>51957608
add three more lines if it matters to you
>>
>>51957323
>Really though, the only optimization concerns that affect the design of your entire application from the beginning are cache, and threading.
not at all, of course there are limits. Realizing when an instruction set implementation is appropriate is another factor, getting around C's integral promotion rules and fp operations for example.
>>
>>51957516
It's called a stack overflow, you can either realloc or accept that memory is finite.

>>51957592
Stroustrup debunked this shit years ago.
Linked lists got deprected by hardware.
https://www.youtube.com/watch?v=YQs6IC-vgmo
>>
>>51957737
stroustrup is a meme

do not take him seriously you dumbass
>>
>>51957760
because you know what is more optimal better than he does
right
>>
>>51957523
>Are you saying that it does not improve performance, or are you saying that the increase in performance is negligible?
not at all, the inline keyword is only a hint to the compiler. Any mainstream optimizing compiler of today will make a better decision in this regard.

Some of the usage I've seen doesn't even take into account what inlining is as the usage is on non small functions which are not called often.
>>
>tfw trying to fully grasp copy constructor/copy assignment operator and move constructor/move assignment operator
Should I be using move as much as possible since its more efficient?

Also when should class member objects be pointers and when should they be regular values.
>>
>>51957823
this is when i stopped learning C++
>>
>>51957760
Experiment for yourself. DRAM is slow as fuck, CPU cache is not and prefetching only works if your data is in contiguous blocks.
>>
>>51957859
i ran 1 million push and 1 million pops and it clocked in at
real    0m0.065s
user 0m0.048s
sys 0m0.016s
>>
OCaml, SML or haskell?
Which is the better language in 2015 and why?
>>
>>51957777
>everything needs to be C performance
LOL
>>
File: 1428792812823.jpg (10KB, 200x213px) Image search: [Google] [Yandex] [Bing]
1428792812823.jpg
10KB, 200x213px
How do I make my game look "nice"?
>>
>>51957823
polymorphism is a good reason to use pointers.

for memory reservation you can use a vector-container most of the time so use that if you can.

call by reference is not a good reason either (in C++ but not C)
>>
>>51957788
> the inline keyword is only a hint to the compiler.
Not entirely true.

Whether the function is actually inlined is up to the compiler, but the presence of the inline keyword changes the semantics (e.g. whether it can be defined in more than one translation unit, whether it's allowed to have static local variables, whether such variables are shared between translation units).

The precise rules are different for C and C++, and for plain "inline" versus "static inline".
>>
>>51957891
I'd go with either OCaml or Haskell, but I don't know enough about either to say which. I really enjoyed Haskell, but OCaml looks great too.

>>51957928
quads dont lie
But seriously, using a linked list for a stack is a) more work and b) much slower, why would you in the first place?

http://pastebin.com/Ff6JRq9e

  ./a.out
Linked List: 90 ms.
Vector: 32 ms.
./a.out
Linked List: 87 ms.
Vector: 37 ms.
./a.out
Linked List: 95 ms.
Vector: 37 ms.
./a.out
Linked List: 88 ms.
Vector: 35 ms.
./a.out
Linked List: 87 ms.
Vector: 31 ms.
./a.out
Linked List: 100 ms.
Vector: 30 ms.
./a.out
Linked List: 96 ms.
Vector: 31 ms.
./a.out
Linked List: 90 ms.
Vector: 29 ms.
./a.out
Linked List: 86 ms.
Vector: 30 ms.
./a.out
Linked List: 87 ms.
Vector: 32 ms.
>>
Reminder that for most practical inputs, a simple, linear algorithm with good memory usage patterns will destroy an asymptotically less complex algorithm that jumps all over the place in memory.
>>
>>51957993
With constant-time or amortized constant-time being an exception, since by nature they don't touch very much memory anyways.
>>
>>51957523
function like macros are a faster alternative to inlined functions and the performance gain is guaranteed.

type safety is lost unless you implement it and they can be tricky to use.
>>
Are there any good tech talks on concurrency that isn't done by some indian or a guy that hasn't spoken to more than 1 person at a time in his life?
>>
>>51957859
> Experiment for yourself.
Of course, the quality of the results will depend upon the quality of the experiment.

E.g. a test case which does practically nothing but push and pop items will strongly favour the vector. Whereas the more "real" work you do alongside that, the smaller the difference. Not only because the stack operations are taking a smaller slice of the pie, but the cache coherence of a specific data structure becomes less significant once a) the other data used by the program is contending for the cache and b) there's "real" code which can be executed while uncached data is being fetched.

Point b) is what most often renders trivial benchmarks meaningless. Out-of-order and speculative execution are fundamental to maintaining throughput on modern CPUs, essentially parallelising single-threaded code. But trivial benchmarks have no real work to parallelise with whatever the benchmark is testing, causing cache misses to stall the pipeline even though that's far less common for real code.

tl;dr: you can only meaningfully benchmark fragments of code as part of the program where they're actually going to be used.
>>
>>51957891
If I were writing code to interface with native libraries, I would probably use OCaml. I much prefer to write in Haskell, but FFI can be a pain in the ass due to laziness and side effecting monads and such.
>>
>>51958043
> function like macros are a faster alternative to inlined functions
Macros typically aren't any faster than a function which is actually inlined. It's not uncommon for them to be slower due to the fact they're not actual functions (particularly if you're simulating a function which returns a value).

> type safety is lost unless you implement it and they can be tricky to use.
Type safety is usually less significant than arguments with side-effects being evaluated more than once.

Function-like macros should be an absolute last resort where they provide a demonstrable gain over inline functions (either in terms of performance or legibility).
>>
>>51958043
>function like macros are a faster alternative to inlined functions and the performance gain is guaranteed.
No. They're not a guarantee of performance gains. Macros can suffer the exact same issues for almost the exact same reasons as inlines do.
>>
>>51957951
well that's just to get around C++ programmers defining functions in header files for some reason so the linker doesn't complain about multiple definitions.

it has no affect on the compiler's decision as whether to inline.
>>
>>51958172
>They're not a guarantee of performance gains.
Of course they are, macros are prepossessed at compile time.

>Macros can suffer the exact same issues for almost the exact same reasons as inlines do.
and those issues are what exactly?
>>
My web framework.

I'm working on Windows now, to see if I can hack a problem out (bad performance). I went from using tcpclient to socket and that increased performance from 5-16ms to around 2ms, but its still not enough as I get 350us on Linux, about a sixth of the speed. The interesting thing is that I was getting exactly whole numbers of millisecond response time (5.001 to 16.001) with tcpclient, Microsoft are definitely doing something suspicious, it'd be really shit if they're introducing lag to make their other software unbeatable.

I'll continue hacking (ie trial and error programming). My latest thoughts is that send/receive are especially expensive on Windows.
>>
>I want every function call to be inlined indiscriminately because CPU instructions don't real and don't need to be loaded from RAM to cache to be used just like every other bit of data
>>
>>51958138
yeah you don't know how preprocessing at all.

asm code is generated for inline functions but not for macros so they are obviously always faster.

>arguments with side-effects being evaluated more than once
preprocessing is just text substitution, expressions are not evaluated.
>>
ok, it seems that using
list.add(index, new element());

doesn't add a new element to the list (making it bigger) but rather work as insertion, changing the element.

BTW it's java.
>>
>>51957940
what kind of game is it? but regardless, as long as you keep a consistent style it should look fine/tolerable
>>
>>51958309
who are you quoting? i actually use __attribute__((noinline,noclone)) on some functions
>>
>>51958443
>Macros are a guarantee of performance gains
>>
>>51958392
I'm not the person you replied to, but I'm going to say YOU don't know how preprocessing or compiler optimisations works.
>asm code is generated for inline functions but not for macros
>but not for macros
What? A macro is going to insert code into your program most of the time. How the hell does it get away with not producing any object code?
Also, don't underestimate the optimiser.
>preprocessing is just text substitution, expressions are not evaluated.
Right. That was exactly his point:
#define my_macro(x) ((x) + (x))

int a = 1;
my_macro(++a);
>>
>>51958228
> Of course they are, macros are prepossessed at compile time.
They're a guarantee of inlining. Inlining is not a guarantee of performance gains. Or at least not a guarantee of sufficient gains to offset the losses from reduced code density.

With an inline function, the compiler can choose to inline it in the cases where there's an actual benefit to doing so (i.e. enabling useful optimisations, particularly loop induction) and using call/return otherwise. With a macro, it's inlined before the compiler even gets to see it.

In theory, the latter can be solved through procedural abstraction (identifying duplicate code and making it a separate procedure). In practice, that feature is only found on compilers for small-scale microcontrollers where minimising code size is essential and the total amount of code is small (identifying duplicates scales non-linearly with code size).
>>
>>51958405
Nah, it's inserition
>Coding OOP without the API docs for the library open
https://docs.oracle.com/javase/8/docs/api/java/util/List.html#add-int-E-
>>
>>51958277
Same guy here.

>I'll continue hacking (ie trial and error programming). My latest thoughts is that send/receive are especially expensive on Windows.
Confirmed false, it still takes between 1ms and 2ms even if I do absolutely no sending and receiving. This is still three times slower than Linux.

What's suspicious is that this is slower than the asp library I'm benchmarking against.
>>
>>51958506
care to explain what's going on?
>>
>>51958476
I just double check and my list.size doesn't increase.
>>
Random question but is there anything wrong with this RAM chip? Considering buying it but it seems so cheap...
http://www.ebay.com/itm/221969421950?ssPageName=STRK:MESELX:IT&_trksid=p3984.m1586.l2649
>>
>>51958506
It may be that windows is just shit at measuring. Programmers are not used to it but every single measurement comes with an associated error, which is at least as big as the smallest unit that the thing can report.
>>
>>51958547
wrong thread
>>
>>51958540
Post code. All I can think of at the moment is that you're using the wrong list subclass.
>>
File: hydrophobic_sand.webm (318KB, 352x264px) Image search: [Google] [Yandex] [Bing]
hydrophobic_sand.webm
318KB, 352x264px
Ask your beloved programming literate anything.
>>
>>51958590
nobody likes you
>>
>>51953857
random browsing on internet
>>
>>51958583
https://github.com/cristianceron/CharacterEditor/blob/master/core/src/character/Character_Atlas.java

line 56
>>
>>51958277
> The interesting thing is that I was getting exactly whole numbers of millisecond response time (5.001 to 16.001) with tcpclient, Microsoft are definitely doing something suspicious
Windows uses a 1000 Hz heartbeat (time-slice). Linux is configurable, typical options are 100, 250, 300 or 1000 Hz (lower numbers give better throughput, higher numbers lower latency).

Any syscall which can't be completed immediately will suspend the calling process to allow another process to run. The calling process will be resumed by the heartbeat once the syscall can complete. Thus, if you measure the time interval between the return from blocking syscalls, the intervals will invariably be an integral number of milliseconds.

Any syscall which needs to block until some other process has performed some action (e.g. communicating with a process via a pipe) will typically exhibit this behaviour.
>>
>>51958621
Looks fine, my bet would be on either chara or the index being null or non valid positions.
Step into it with the debugger man.
>>
File: (47).png (260KB, 563x542px) Image search: [Google] [Yandex] [Bing]
(47).png
260KB, 563x542px
>tfw writing inefficient code
>>
>>51958533
I have two ways of opening and closing network connections.
One uses the httplistener class.
The other uses the socket class.

Httplistener is benchmarking at 150us (no shit) on Windows, but about 1ms on Linux.
Socket is benchmarking at 1.5ms on Windows, but about 350us (probably less) on Linux.

Ideally, there should be nothing simpler, and therefore faster, than a raw socket. Microsoft are doing some shit, I'd think httplistener is connecting to IIS, but not, because then it wouldn't work on mono.

BTW, 1ms == 1000us.

>>51958550
No, I'm getting my measurements with apachebench, and if you were right httplistener wouldn't benchmark so fast.
>>
>>51958669
I dunno, it simply works.

ain't gonna fix what ain't broke.
>>
>>51958679
I'm fine with that as long as you admit that you either don't care or aren't skilled enough to do otherwise, and not saying "wow guys it's 2015 computers are fast now :^)".

Dumb frogposter.
>>
File: kek.jpg (181KB, 788x1014px) Image search: [Google] [Yandex] [Bing]
kek.jpg
181KB, 788x1014px
>>51958679
>tfw barely designing and then implementing a "stringly typed" scripting language parser
>>
>>51958712

>stringly typed
Everything is a string?
>>
>>51958695
you sound triggered. heh. truth is, i choose to write inefficient code because it's easier. it's not like computers nowadays in the year 2015 can't handle the extra computation processes per second :^)
>>
>>51958741
Pretty much. If the strings are numeric you can do math, etc, but there's no real type system and all function parameters in the underlaying built in functions are strings.
>>
>>51958654
Interesting, but then how does httplistener get its speed? Is it possible to open a connection without a syscall?

>>51958679
I'm also fine with that, provided you don't volunteer for anything that bottlenecks (or don't work with me at all)

>>51958786
Fast servers are a security measure.

With a slow server, a ddos will shut it down. With a fast server, a ddos will slow it down. The alternative is finding some magical method of distinguishing a genuine response, like cloudfront.
>>
>>51958786
I agree with this guy. I write all my code to perform the same operation 1000 times in for loops, unless of course in doing so would change the behavior of my program in which case I just sleep for 10ms after such calls.
>>
>adding delays to your program for the sole reason to make it appear like it's doing something important
kill yourselves
>>
>>51958864
>making your program look trivial because it does fucking nothing
enjoy losing clients, dumbshit
people are dumb, they expect their programs to take a long time so they seem large and complex
>>
>>51958864
just added a sleep(10000) to my program

nigger
>>
>>51958864
>Tfw classmate added a sleep() to the input handling code so it wouldn't pick up key too fast
I sometimes wonder how they get so far in the classes while being so shit
>>
                foreach (string subDirectory in Directory.GetDirectories(lblFolderBrowse.Content.ToString()))
{
foreach (var element in Directory.GetFiles(subDirectory.ToString()))
{
file = System.IO.Path.GetFileName(element);
lstAllFiles.Items.Add(subDirectory.ToString() + @"\" + file);
}
}


How the fuck do I parse out JUST the subdirectories folder name, instead of the full path? I've never had to do something like this before.
>>
>>51959185
Discard everything preceding the last "\" from the string.
You can do it manually or with a regular expression.
Or are you asking something different?
>>
File: pls.png (144KB, 883x1547px) Image search: [Google] [Yandex] [Bing]
pls.png
144KB, 883x1547px
i just want the goddamn taylor series

why does everything have to be so fucking broken
>>
>>51959252
Nope, that's what I'm after.

Adding this feature to my program is a killer, I've now gotta go through everything that interacts with the files in the subdirectories and write a method to find entries of type [subdirectory]/[filename] and remove the crap.
>>
>>51959185
maybe you should just kill yourself lmao
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on wi
n32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pprint import pprint
>>> import os
>>> print os.getcwd()
C:\
>>> dirs = os.walk('.').next()[1]
>>> pprint(dirs)
['$Recycle.Bin',
'Boot',
'Documents and Settings',
'eSupport',
'Fraps',
'Intel',
'NVIDIA',
'PerfLogs',
'Program Files',
'Program Files (x86)',
'ProgramData',
'Python27',
'Recovery',
'System Volume Information',
'Users',
'Windows']
>>>
>>
>>51959301
Why don't you just calulate it "manually"?
You can ask Wolframfor the derivates.
Personally I would just check the periodicity of the function you're using and make a lookup table with a certain precision.
>>
So what's the status on things like WebAssembly and asm.js?

Can I really start developing web applications without needing to deal with hipster JS frameworks and other cancerous shit?
>>
File: 1450596004297.png (288KB, 907x1855px) Image search: [Google] [Yandex] [Bing]
1450596004297.png
288KB, 907x1855px
>>51959399
i have no idea what you're talking about

i just want something like in the widget at the top but with more digits of precision. it's not too much to ask when the example in >>51959301 does exactly that. you think i should calculate the expression below manually to 16+ digits of precision?
>>
>>51959252
Now I'm having trouble removing folder name from [subdirectory]\[filename]

I want off this wild ride.
>>
/g/ has some of the dumbest opinions on languages I've ever read

what makes you all so fucking retarded?
>>
>>51959472
The precision of a Taylor series depends on how many terms you're doing as well as how far you're from the point. And well, the usual precision of of float/double.
If you can't calculate the actual derivatives of the expression because you want something generic, you can aproximate them by numerical methods, but you'll lose precision there too.
If you want extra precision you should probably begin by trying to figure out the error cap of your aproximations at a given point, otherwise the extra digits will be pointless noise.

I don't know what you want this for so I can't really give you any concrete tips other than it's really hard to get really good precision that is cheaper than calculating the actual function.
>>
>>51959592
most people here are hobbyists and amateurs who have never written anything more substantial than a fizzbuzz implemented as a linked list.
>>
>>51957874
>never posting how fast the array version is
>>
>>51957891
There is only minor differences between SML and Ocaml. I personally like the SML syntax better, pattern matching and function definitions look clearer, there are no special floating point arithmetic operators (ie +.) at the cost of having to define explicit types in functions that use arithmetic. But there is more learning material for Ocaml. Haskell is ok if you just want to study fp and not actually do any programming with it. I personally think Haskell is overkill if you want to do anything practical compared with ML languages.
>>
>>51959618
it doesn't matter
if your program is doing anything substantial, other more integral parts of your application will have much worse time complexity than a fucking linked list stack.
>>
Familarizing myself with C++11 and multi-threading.

I have a feeling that this style of programming leads to very insidious bugs. It's interesting to try and figure out how you can make thread safe data structures though. Making it so you're Mutex locks the data up at the right granularity seems like it may take some practice before I get a feel for it.
>>
How do I implement a strstr?
>>
>>51959634
it's always the DB desu
>>
>>51959592
shut your ass
>>
I bought an old Commadore 64 keyboard. I'm trying to research how possible it would be to acquire the parts, write my own firmware, and convert the old connection this thing has into a USB connection.
>>
>>51959704
just buy a mechanical keyboard, you'll actually use it unlike that trash heap
>>
>>51959634
But the array/vector version is fewer lines to implement and maintains cache coherency. There is literally no reason not to use it. The people who advocate for linked lists are just memers.
>>
>>51959743
>cache coherency
>he fell for the CPU pipeline meme
>>
>>51959753
>he's never read the Intel Software Developer's Manuals
>>
>>51959768
>developing for a specific CPU platform
fuck off
>>
>>51956360
I have a deep love for the modulo interpolation syntax but it's true str.format is more flexible/robust. I'm not so sure it's a matter of aesthetics as wanting more powerful string formatting without breaking the existing idiom. I can see the logic but I don't think can't just extend the modulo syntax to cover the new features format has.
>>
>>51959727
I mean I already have a mechanical keyboard. I just want to do this for fun.
>>
File: advent tree.jpg (124KB, 699x649px) Image search: [Google] [Yandex] [Bing]
advent tree.jpg
124KB, 699x649px
Who else /40stars/ here? Couldn't code up a solution for day 19 part 2 though, had to use someone else's non-coding-based analysis solution
>>
>>51959868
cheater
>>
Wait, are you faggots still going on about the LL vs vector stack?

They both do fine, yes vectors are negligibly faster under most benchmarks but at cost of some important traits (immutability, simplicity of implementation, generally smaller memory requirement).
>>
>>51959868
Totally forgot about that. I finished only the first two starts when I heard about it
>>
>>51959877
Shit's hard yo. Leaderboards only filled up after 4 hours

--- Part Two ---

Now that the machine is calibrated, you're ready to begin molecule fabrication.

Molecule fabrication always begins with just a single electron, e, and applying replacements one at a time, just like the ones during calibration.

For example, suppose you have the following replacements:

e => H
e => O
H => HO
H => OH
O => HH
If you'd like to make HOH, you start with e, and then make the following replacements:

e => O to get O
O => HH to get HH
H => OH (on the second H) to get HOH
So, you could make HOH after 3 steps. Santa's favorite molecule, HOHOHO, can be made in 6 steps.

How long will it take to make the medicine? Given the available replacements and the medicine molecule in your puzzle input, what is the fewest number of steps to go from e to the medicine molecule?


Sample input:
Al => ThF
Al => ThRnFAr
B => BCa
B => TiB
B => TiRnFAr
Ca => CaCa
Ca => PB
Ca => PRnFAr
Ca => SiRnFYFAr
Ca => SiRnMgAr
Ca => SiTh
F => CaF
F => PMg
F => SiAl
H => CRnAlAr
H => CRnFYFYFAr
H => CRnFYMgAr
H => CRnMgYFAr
H => HCa
H => NRnFYFAr
H => NRnMgAr
H => NTh
H => OB
H => ORnFAr
Mg => BF
Mg => TiMg
N => CRnFAr
N => HSi
O => CRnFYFAr
O => CRnMgAr
O => HP
O => NRnFAr
O => OTi
P => CaP
P => PTi
P => SiRnFAr
Si => CaSi
Th => ThCa
Ti => BP
Ti => TiTi
e => HF
e => NAl
e => OMg

ORnPBPMgArCaCaCaSiThCaCaSiThCaCaPBSiRnFArRnFArCaCaSiThCaCaSiThCaCaCaCaCaCaSiRnFYFArSiRnMgArCaSiRnPTiTiBFYPBFArSiRnCaSiRnTiRnFArSiAlArPTiBPTiRnCaSiAlArCaPTiTiBPMgYFArPTiRnFArSiRnCaCaFArRnCaFArCaSiRnSiRnMgArFYCaSiRnMgArCaCaSiThPRnFArPBCaSiRnMgArCaCaSiThCaSiRnTiMgArFArSiThSiThCaCaSiRnMgArCaCaSiRnFArTiBPTiRnCaSiAlArCaPTiRnFArPBPBCaCaSiThCaPBSiThPRnFArSiThCaSiThCaSiThCaPTiBSiRnFYFArCaCaPRnFArPBCaCaPBSiRnTiRnFArCaPRnFArSiRnCaCaCaSiThCaRnCaFArYCaSiRnFArBCaCaCaSiThFArPBFArCaSiRnFArRnCaCaCaFArSiRnFArTiRnPMgArF
>>
How do I get started with embedded C programming?

I had an arduino but I broke it.
>>
>>51959949
>program C
>embed it
>>
Hi /g/, I don't really frequent the programming threads, and I don't code... But my kid wants to learn how and I really don't know where to start. Should I set him up on codeacademy or something of the sort?
>>
Not even a Java guy but Holy fuck Scala is great
>>
>>51960072
How old? Haskell is good.
>>
don't force your kid to program. let him play outside. kids should play outside
>>
>>51960100
He's 11
What the hell is haskell? Googling it.

I've made him an account of KhanAcademy and he's gotten through the entire basic JavaScript section they have there and is moving onto Html/CSS. He likes it a lot and I think he's stuck with it because he can see immediate progress since all their lessons are pretty interactive.
>>
>>51960171
Eh, I'm not forcing him, he asked him and I'm trying to help. If he stops liking it I won't push him.
>>
>>51960186
http://learnyouahaskell.com/

It'll teach him to think mathematically. Much better than turning him into a mindless code monkey who only knows Javascript.
>>
>>51960072
Scratch to familiarise him with basic programming concepts

Then Python
>>
>>51960234
It literally takes years to recover from learning Python. You pick up nothing but bad habits.
>>
>>51960200
tell him to get some fresh air. he should be outside get some fresh air
>>
>>51960241
not this meme again
>>
>>51960284
I understand you don't have "fresh" air in Delphi, Sanjay, but you don't have to live vicariously through the lives of another anon's child. There is literally nothing wrong with learning how to program.
>>
new thread when ? :3
>>
>>51960466
Once you kill yourself.
>>
>>51958826
>>51958688
>>51958506
>>51958277
This guy again.

Figured it out, Windows is slow until you use socketasynceventargs. Still slower than httplistener, but I'm down to 210us for Windows. The other thing I was using, iasync or whatever, is old code.

>>51959949
>arduino
Naw.

Actually, there's exactly nothing wrong with arduino, maybe a little expensive for the cpu power it gets you. It's more that if you tell anyone they look at you as if you stepped in dog shit, something between pity and disdain.

Look for a prototyping board (any) that has an arm chip. Make sure the board comes with software or some directions to software to load programs. Kiel is okay, but it's been a while since I've studied these.
>>
How to write a proper stack:

#include <new>
#include <cstdlib>

template <class T>
class Stack {
T *data;
size_t len;
size_t cap;
public:
Stack()
{
data = (T*) malloc(sizeof(T));
if (nullptr == data) throw std::bad_alloc();
len = 0;
cap = 1;
}

~Stack()
{
free(data);
data = nullptr;
}

template <class... Args>
void emplace(Args&&... args)
{
if (len >= cap) {
cap *= 2;
T *tmp = (T*) realloc(data, cap * sizeof(T));
if (nullptr == tmp) throw std::bad_alloc();
else data = tmp;
}
data[++len-1] = T(args...);
}

bool empty() const { return (0 == len); }
void pop() { if (len) len--; }

void push(const T& elem)
{
if (len >= cap) {
cap *= 2;
T *tmp = (T*) realloc(data, cap * sizeof(T));
if (nullptr == tmp) throw std::bad_alloc();
else data = tmp;
}
data[++len-1] = elem;
}

void reserve(size_t c)
{
if (cap >= c) return;
cap = c;
T *tmp = (T*) realloc(data, cap * sizeof(T));
if (nullptr == tmp) throw std::bad_alloc();
else data = tmp;
}

void shrink_to_fit()
{
data = (T*) realloc(data, len * sizeof(T));
cap = len;
}

size_t size() const { return len; }
T& top() { return data[len-1]; }
const T& top() const { return data[len-1]; }
};


I'm bored, and also procrastinating.
>>
>>51960826
http://www.cplusplus.com/reference/stack/stack/
>>
>>51960826
mfw copying

Stack stack;
Stack stack2 = stack;
>>
>>51960838

I mostly based this one off of the STL stack, but didn't implement swap or the comparison operators, and did implement reserve() and shrink_to_fit(), as they would be for std::vector.
>>
>>51960851

>I forgot a copy constructor
Fugg...
>>
File: 1441684460338.jpg (92KB, 1280x720px) Image search: [Google] [Yandex] [Bing]
1441684460338.jpg
92KB, 1280x720px
>>51960826
>>
>>51960826
>using c++ idioms (including recent ones from c+11)
>using malloc instead of new
>having this class fail for any T that isn't a POD type

nigger you just went full stroupstard
>>
>>51960826
>c+++
>c's cast
lel
>>
>>51960906

>using malloc instead of new
Can't use realloc() with new.

>having this class fail for any T that isn't a POD type
Give an example where this fails.
>>
>>51960826
>How to write a proper stack:

>C++

Rejected. And you're fired.
>>
>>51960826
Hey Ruby, have you done much graphics programming? Any hot tips?
>>
>>51960949
That's not idiomatic C++. In C++, a better way of dealing with reallocation is to use a standard library container, such as vector, and let it grow naturally.
>>
>>51961032
Idiomatic C++ would be to just use std::queue or even std::deque directly instead of rolling your own, broken, Stack implementation.
>>
>>51961059
Or just use a friggin' linked list in the first place? It's not hard and never runs out of memory.
>>
File: n.png (150KB, 587x855px) Image search: [Google] [Yandex] [Bing]
n.png
150KB, 587x855px
>>51960826
>c++
>>
>>51961032

And how do you think vector works under the fucking hood? Protip: Not with new/delete.

>>51961070

We've been over this. Linked lists are slow as dogshit for this task.

>>51960979

I have little to no experience with graphics shit. All I can say is know your fucking matrices.
>>
>>51960949
>can't use muh realloc()!
then use malloc/realloc and placement new, faggot.

it will fail when you pass it any fucking class with a non-trivial constructor, dumbass
>>
>>51961121
Like Notch can talk with all Minecraft's performance issues. Minecraft was a decent idea hampered by shitty programming.
>>
>>51961140
>how do you think vector works under the fucking hood? Protip: Not with new/delete.
it absofuckinglutely does you fucking moron
>>
>>51961166
Agreed. There are a lot of clones done in an appropriate language and they all run a lot faster on even 10 year old PCs.
>>
>Library requires me to install a second language to build it.
lets be honest here, despite all the c++ sucks memes it's not a bad language.

But it has one massive flaw and that's the lack of an standardized cross platform build system.
Everyone does kind of whatever the fuck he wants. I don't want to use a different build system for every fucking dependency.

It really makes me wanna punch a hole in the wall
>>
>>51961182
Actually it uses whatever the second template parameter, the allocator, does.
>>
>>51956401
>implying I'm a webdev pleb
>>
>>51961140
>Protip: Not with new/delete.
[Citation Needed]
I'm pretty sure it uses std::allocator which I think uses new/delete.
>>
>>51961206
What makes C++ bad is the fact that its heritage means it has to do very funky things to implement its features within C-like syntax. C++ is a great language in terms of the features available give its nature. C++ is bad in terms of how ugly the syntax and implementation needs to be.
>>
>>51961223
>>51961182
http://stackoverflow.com/questions/2096571/how-is-c-stdvector-implemented
This was interesting.
>>
>>51961140
void push_back(const value_type& _Val)
{ // insert element at end
if (_Inside(_STD addressof(_Val)))
{ // push back an element
size_type _Idx = _STD addressof(_Val) - this->_Myfirst;
if (this->_Mylast == this->_Myend)
_Reserve(1);
_Orphan_range(this->_Mylast, this->_Mylast);
this->_Getal().construct(this->_Mylast,
this->_Myfirst[_Idx]);
++this->_Mylast;
}
else
{ // push back a non-element
if (this->_Mylast == this->_Myend)
_Reserve(1);
_Orphan_range(this->_Mylast, this->_Mylast);
>>>>>>this->_Getal().construct(this->_Mylast,
_Val);
++this->_Mylast;
}
}

further down the callstack:

    void construct(_Ty *_Ptr, const _Ty& _Val)
{ // construct object at _Ptr with value _Val
::new ((void *)_Ptr) _Ty(_Val);
}


>>51961217
>>
>>51961145

Placement new is not a valid replacement for realloc. realloc may use the same memory address and expand as normal, or it may grab a larger buffer somewhere else if the current buffer cannot be expanded to the size needed, and it will copy over the data as is. Meanwhile placement new merely uses the same memory address again. And since it's new and not malloc, we end up calling a constructor that we don't fucking want.

>non-trivial constructors
push calls the copy constructor
emplace calls whatver constructor you have with arguments.

What non-trivial constructor do you need that cannot be invoked by either of these?
>>
>>51961257

Now I am extremely curious how the hell shrink_to_fit and reserve are implemented in the vector class, because they specifically need to resize an existing buffer in place without initializing anything, which isn't how new and delete work.
>>
>>51961257
>::new ((void *)_Ptr) _Ty(_Val);
That is placement new, nothing more than calling the constructor of _Ty at the location _Ptr.
The real allocation happens in _Reserve.
>>
>>51961293
They do not do it in place, they allocate the new buffer and move the objects.
(Actually, vector only moves the objects if the move constructor is nothrow(true) and copies otherwise)
>>
>>51961321
noexcept(true), of course.
>>
>>51961293
objecs need to know tthat hey are moved for obvious reasons.
>>
>>51961293
>Placement new is not a valid replacement for realloc
that's not what i was arguing, you cockwad. use malloc/realloc and then use placement new to call the constructors with that memory
just stop arguing, your autism is showing.

>>51961293
template<class _Ty> inline
_Ty *_Allocate(size_t _Count, _Ty *)
{ // allocate storage for _Count elements of type _Ty
void *_Ptr = 0;

if (_Count == 0)
;
else if (((size_t)(-1) / sizeof (_Ty) < _Count)
|| (_Ptr = ::operator new(_Count * sizeof (_Ty))) == 0)
_Xbad_alloc(); // report no memory

ret
>>
>>51961293
Placement new and both reserve and shrink is allowed to invalidate iterators, meaning they can move memory.
Also, shrink_to_fit doesn't have to actually do anything, a valid implementation is just: return;
>>
I've been programming C for 5 years and I have no idea what the fuck you assholes are talking about. Why is C++ so shitty?
>>
>>51961358

TL;DR: STL Vectors apparently cannot resize in place, even if there is room for it, as realloc() would allow.
>>
>>51961358
well at least you aren't a java monkey that thinks memory allocation is free and that memory grows on trees
>>
>>51961403
Maybe not a java monkey, but I'm c# and from the same paradigm... We too don't allocate memory without regards, it turns out reusing the same objects is faster for us too.

Difference is we don't get massive slow downs for accidentally calling the copy constructor.

BTW, down to 190us. I'll probably be able to shave 20us tomorrow with a new header parsing loop, I have an idea that calls receive as few times as possible but still parses data whilst its still being sent from the client.
>>
why won't my java code compile?

here's the error:
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'build' failed
make: *** [build] Error 1

Compilation exited abnormally with code 2 at Sun Dec 20 06:56:37


here's myu code:
class JTestbuild2
{
public static void main(String[] args)
{
System.out.println("Nice meme!");
}
}
>>
>>51961402

int main(int argc, char** argv)
{
int times = 10000;
int in_place = 0;
int moved = 0;
int sz = 1;
int* array = (int*)malloc(sizeof(int) * sz);

while(sz < times)
{
int* first = &array[0];
array = (int*)realloc(array, ++sz);
if(first == &array[0])
in_place++;
else
moved++;
}

std::cout << "after " << times << " reallocations, " << in_place << " were in-place, while "
<< moved << " were moved.\n";

std::vector<int> varray;
varray.push_back(0);

in_place = 0;
moved = 0;
sz = 1;
while(sz++ < times)
{
int* first = &varray[0];
varray.push_back(1);
if(first == &varray[0])
in_place++;
else
moved++;
}

std::cout << "after " << times << " push_back() calls, " << in_place << " were in-place, while "
<< moved << " were moved.\n";

return 0;
}

output on my implementation:

after 10000 reallocations, 9994 were in-place, while 5 were moved.
after 10000 push_back() calls, 9976 were in-place, while 23 were moved.


btw you are an autist and i strongly suspect you have full-blown assburgers.
>>
>>51961466
lol are you seriously trying to optimize time-critical code in c#? you know it's jit-interpreted like java, right? clr == jvm, basically
just make some calls to native code if you really need the speed.
>>
>>51961530
You can compile C# to native code.
>>
Why can't java do this?
for(int i = 0; true; i > 9 ? break : continue)
{
System.out.println(i++);
}

why does java hate its coders
>>
>>51961514

Your two sections of code are not doing the same thing. First of all, push_back does not necessarily allocate new memory with every call. Instead, it over-allocates, and then will typically multiply the capacity by some constant factor when new memory is needed, and then move data over when it reallocates. Meanwhile, your first section of code is demonstrating what realloc is supposed to do - increase the size of the buffer, copying data over if the new buffer must be in a different location.

What I am stating is this: when std::vector triggers a reallocation from a push_back, it is not capable of using the same memory location as before after a reallocation, while a vector based on realloc is capable of doing so, allowing for performance increases. This is contrary to my previous assumption that STL containers were efficient about their memory allocations.
>>
>>51961549
Never mind I figured out a better way to do it.
for(int i = 0; i < 9; System.out.println(i++)){}
>>
>>51961530
That's next.

After I've got a pure C# perfect, I'll work on version 2.0 codenamed with an equally stupid females name and use boost for the connections and maybe even parse headers in C++. I'll have to use reverse pinvoke to allow C# users to have a similar api as what I've got at the moment, next time I'll pass a struct though.

I reckon I can get response times as low as 80us like that.
>>
>>51961514
You're comparing apples to oranges here.
realloc() == vector.reserve()
push_back() is amortized with a geometric progression and only reallocates (i.e calls reserve) approximately log n times.
>>
>>51961571
>What I am stating is this: when std::vector triggers a reallocation from a push_back, it is not capable of using the same memory location as before after a reallocation
there is nothing stopping std::vector from using realloc, though. point is, if new/delete are used as the allocator, it will call new/delete because it needs to in order to support non-trivial (non POD) data (e.g. practically any class).
>>
>>51961571
>>51961571
my point is, internally realloc() uses a similar strategy: it will request chunks of data from the operating system at a size greater than needed, and will keep track of how much of those chunks are used. when the size increases beyond the available, it will request more blocks of memory from the os and move the data if need be.
>>
>try to write program that reverses a singly linked list
>get it right on first compile
Am I starting to understand pointers?
>>
/!\ A L E R T /!\

new thread

>>51961669
>>51961669 >>51961669
>>51961669 >>51961669 >>51961669
>>51961669 >>51961669 >>51961669
>>51961669 >>51961669
>>51961669

/!\ A L E R T /!\
Thread replies: 255
Thread images: 17
[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