|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On November 11 2014 07:14 Cynry wrote:+ Show Spoiler +relevant code in the .c int get_next_line(int const fd, char **line) { int ret; static t_list *files; t_list *cursor; t_file *new_file;
ret = 0; if (files) { cursor = files; while (cursor && cursor->content && ((t_file *)cursor->content)->fd != fd) cursor = cursor->next; if (cursor->content && ((t_file *)cursor->content)->fd == fd) ret = ft_read_file(fd, cursor->content, line); } else { if (!(files = (t_list *)ft_memalloc(sizeof(*files)))) return (-1); if (!(new_file = (t_file *)ft_memalloc(sizeof(*new_file)))) return (-1); cursor = ft_lstnew(new_file, sizeof(*new_file)); ((t_file *)cursor->content)->fd = fd; ((t_file *)cursor->content)->left_over = 0; ft_lstadd(&files, cursor); ret = ft_read_file(fd, cursor->content, line); } return (ret); } in the .h #ifndef GET_NEXT_LINE_H # define GET_NEXT_LINE_H
# define BUFF_SIZE 32 # define EOF "\n"
#include <string.h>
typedef struct s_list { void *content; size_t content_size; struct s_list *next; } t_list;
typedef struct s_file { int fd; char *left_over; } t_file; The segfault happens with the second call to get_next_line, when if (files) is checked and the program tries to access cursor->content->fd. files is never set to anything?
|
You got me closer and some more errors to corret :D Thanks !
Edit : and after 5 more minutes of debugging I got it working, merci beaucoup !
|
On November 11 2014 07:42 zzdd wrote:Show nested quote +On November 11 2014 07:14 Cynry wrote:+ Show Spoiler +relevant code in the .c int get_next_line(int const fd, char **line) { int ret; static t_list *files; t_list *cursor; t_file *new_file;
ret = 0; if (files) { cursor = files; while (cursor && cursor->content && ((t_file *)cursor->content)->fd != fd) cursor = cursor->next; if (cursor->content && ((t_file *)cursor->content)->fd == fd) ret = ft_read_file(fd, cursor->content, line); } else { if (!(files = (t_list *)ft_memalloc(sizeof(*files)))) return (-1); if (!(new_file = (t_file *)ft_memalloc(sizeof(*new_file)))) return (-1); cursor = ft_lstnew(new_file, sizeof(*new_file)); ((t_file *)cursor->content)->fd = fd; ((t_file *)cursor->content)->left_over = 0; ft_lstadd(&files, cursor); ret = ft_read_file(fd, cursor->content, line); } return (ret); } in the .h #ifndef GET_NEXT_LINE_H # define GET_NEXT_LINE_H
# define BUFF_SIZE 32 # define EOF "\n"
#include <string.h>
typedef struct s_list { void *content; size_t content_size; struct s_list *next; } t_list;
typedef struct s_file { int fd; char *left_over; } t_file; The segfault happens with the second call to get_next_line, when if (files) is checked and the program tries to access cursor->content->fd. files is never set to anything?
It's very rare that you ever really want to use the static keyword in a function or local scope. It's basically the same as moving the declaration into the global scope, which is usually clearer that only one instance of that variable exists. Otherwise, the code looks fine at my glance.
Set a breakpoint at the line it's segfauling and check the cursor and the fd it's trying to access. It looks like it might be going off of the list into random memory, then when you try to look up the fd, you end up in protected memory and segfault.
If you arent using a debugger, then just printf everything in the while loop.
|
he guys, Im currently following a community college level app development study and my school is inviting companies in my area so we can get an internship in our last semester.
any tips?
edit, something I did left out was that I have to hold a presentation about a social media website that I made with a group (well.. its more that I did 30% of the work, 1 guy the rest and the others 0 lines of code) are there anythings I should focus on or try to avoid in my presentation?
|
|
|
did a quick (and prolly inaccurate) comparison of some different variant implementations. only dispatch, is timed. construction on mine (heap based) is way slower, but only occupies as much memory as it needs to hold the value type it is instantiated with. the implementation of core is amazingly cool i think.
stack based jason core boost heap based jeh
+ Show Spoiler +#include<iostream> #include<functional> #include<memory> #include<vector> #include<type_traits> #include<seq/sequence.hpp> #include<abstract/abstract.hpp> #include<abstract/deconstruct.hpp> #include<../cppcon14/variant.h> #include<../core/include/core/variant.hpp> #include<boost/variant.hpp> #include<seq/seq.hpp> #define BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS 5 #include<boost/variant/multivisitors.hpp> #include<time.h> #include<random> #include<pthread.h>
long operator-(const timespec& end,const timespec& start) { if ((end.tv_nsec-start.tv_nsec)<0) { return 1000000000+end.tv_nsec-start.tv_nsec; } else { return end.tv_nsec-start.tv_nsec; } }
const int N=100000; const int M=2;
std::random_device rd; std::default_random_engine e1(rd()); std::uniform_int_distribution<int> dist(0,M-1);
template<int i> struct type{};
template<template<class...> class,class> struct variant_maker;
template<template<class...> class variant,int... index> struct variant_maker<variant,seq::integer_sequence<index...>>{ using output=variant<type<index>...>; };
template<template<class...> class variant> using make_variant=typename variant_maker<variant,seq::integer_range<0,M>>::output;
using abstract_t=make_variant<jeh::abstract>; using jason_variant_t=make_variant<cppcon14::variant::variant_t>; using core_variant_t=make_variant<core::variant>; using boost_variant_t=make_variant<boost::variant>;
struct unary_t:boost::static_visitor<void>{ using fn1_t=void(); template<class T> void operator()(const T&){} }; unary_t unary; struct binary_t:boost::static_visitor<void>{ using fn2_t=void(); template<class T,class U> void operator()(const T&,const U&){} }; binary_t binary; struct tetriary_t:boost::static_visitor<void>{ template<class... T> void operator()(const T&...){} }; tetriary_t tetriary;
timespec t0,t1;
template<class variant,int i> variant random_maker(){ return variant((type<i>())); }
template<class variant> using random_makers_t=std::array<variant(*)(),M>;
template<class variant,int... I> constexpr random_makers_t<variant> random_makers(const seq::integer_sequence<I...>&){ return {random_maker<variant,I>...}; }
template<class variant> variant make_random(){ static constexpr auto make_randoms =random_makers<variant>(seq::integer_range<0,M>()); return make_randoms[dist(e1)](); }
template<class predicate,class variant> using dispatch_enabler=std::enable_if_t<std::is_same<variant,predicate>::value,long>;
template<class variant> dispatch_enabler<jason_variant_t,variant> timed_unary_dispatch() { auto var=make_random<variant>(); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t0); cppcon14::variant::apply(unary,var); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t1); return(t1-t0); }
template<class variant> dispatch_enabler<variant,abstract_t> timed_unary_dispatch() { auto var=make_random<variant>(); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t0); jeh::deconstruct<void>(unary,var); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t1); return(t1-t0); }
template<class variant> dispatch_enabler<variant,core_variant_t> timed_unary_dispatch() { auto var=make_random<variant>(); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t0); var.visit(unary); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t1); return(t1-t0); }
template<class variant> dispatch_enabler<variant,boost_variant_t> timed_unary_dispatch() { auto var=make_random<variant>(); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t0); boost::apply_visitor(unary,var); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t1); return(t1-t0); }
template<class variant> long unary_test(){ std::vector<long> times; for(int i=0;i<N;++i){ times.push_back(timed_unary_dispatch<variant>()); } return std::accumulate(std::begin(times),std::end(times),0)/times.size(); }
template<class variant> dispatch_enabler<variant,boost_variant_t> timed_binary_dispatch() { auto var0=make_random<variant>(); auto var1=make_random<variant>(); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t0); boost::apply_visitor(binary,var0,var1); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t1); return(t1-t0); }
template<class variant> dispatch_enabler<variant,jason_variant_t> timed_binary_dispatch() { auto var0=make_random<variant>(); auto var1=make_random<variant>(); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t0); cppcon14::variant::apply(binary,var0,var1); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t1); return(t1-t0); }
template<class variant> dispatch_enabler<variant,abstract_t> timed_binary_dispatch() { auto var0=make_random<variant>(); auto var1=make_random<variant>(); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t0); jeh::deconstruct<void>(binary,var0,var1); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t1); return(t1-t0); }
template<class variant> long binary_test(){ std::vector<long> times; for(int i=0;i<N;++i){ times.push_back(timed_binary_dispatch<variant>()); } return std::accumulate(std::begin(times),std::end(times),0)/times.size(); }
template<class variant> dispatch_enabler<variant,abstract_t> timed_tetriary_dispatch() { auto var0=make_random<variant>(); auto var1=make_random<variant>(); auto var2=make_random<variant>(); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t0); jeh::deconstruct<void>(tetriary,var0,var1,var2); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t1); return(t1-t0); } template<class variant> dispatch_enabler<variant,boost_variant_t> timed_tetriary_dispatch() { auto var0=make_random<variant>(); auto var1=make_random<variant>(); auto var2=make_random<variant>(); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t0); boost::apply_visitor(tetriary,var0,var1,var2); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t1); return(t1-t0); }
template<class variant> long tetriary_test(){ std::vector<long> times; for(int i=0;i<N;++i){ times.push_back(timed_tetriary_dispatch<variant>()); } return std::accumulate(std::begin(times),std::end(times),0)/times.size(); }
int main(){
std::cout<<"\n---------- unary visit ----------\n\n"; std::cout<<" jason: "<<unary_test<jason_variant_t>()<<std::endl; std::cout<<" core: "<<unary_test<core_variant_t>()<<std::endl; std::cout<<" jeh: "<<unary_test<abstract_t>()<<std::endl; std::cout<<" boost: "<<unary_test<boost_variant_t>()<<std::endl; std::cout<<"\n------------------------------------\n\n";
std::cout<<"---------- binary visit ----------\n\n"; std::cout<<" jason: "<<binary_test<jason_variant_t>()<<std::endl; std::cout<<" boost: "<<binary_test<boost_variant_t>()<<std::endl; std::cout<<" jeh: "<<binary_test<abstract_t>()<<std::endl; std::cout<<"\n------------------------------------\n\n";
std::cout<<"---------- tetriary visit ----------\n\n"; std::cout<<" boost: "<<tetriary_test<boost_variant_t>()<<std::endl; std::cout<<" jeh: "<<tetriary_test<abstract_t>()<<std::endl; std::cout<<"\n------------------------------------\n\n";
}
removed output as it was misleading. i have run it more and varied the the number of types involved in abstraction. i think final verdict is boost being consistently faster in all cases, core has the slight upper hand on the other two. jasons is consistently a bit slower than jeh in binary dispatch, but everyone usually within 10 ns of eachother (~220-260 ns).
presonally i'd use the core one (if i wasn't biased towards my own).
|
for a class i have to come up with an idea to research with regards to Distributed Systems....
last night i came up with a draft abstract....by sheer willpower and luck lol :D
have a read and comment if you want....i cant ask any specific questions right now coz im TIRED!
+ Show Spoiler + (intro) The Actor model of concurrent processing was inspired by the idea that the core of all computing is the passing of messages. With this as a basis, a decoupling of the sender and receiver of messages allows processes (or Actors) in the Actor model to operate asynchronously. This works to avoid the locking that is required when threads attempt to access data within a traditional shared-state model of concurrent processing.
(abstract) The Actor Model is an emerging methodology that offers an alternative approach to the traditional shared-state model of parallel programming. Although much debate surrounds the usefulness of the Actor Model in real-world application, this debate tends to surround issues of architectural design rather than runtime performance. This paper aims to evaluate the performance of the Actor Model by measuring the execution time of a scalable multi-threaded application and then comparing this with a similar build based on a traditional shared-state model.
i guess the main obvious questions/steps are
a) how has this been done before? (i doubt it has been done with javascript implementation) b) how can it be implemented? c) how can it be implemented in a non-trivial fashion?
for example, will two similar trivial applications in the same programming language but using different code structure show any difference in performance to one another? (feel free to comment on this because I don't know the answer).
how can i make my application scalable to try to uncover differences in performance?
c) how can it be measured?
ok so im not that tired apparently lol
Edit (copy pasta):
With regards to my Final Year Project that several of you advised me on, I firstly proposed to my tutor that I look at a subject in cloud computing but he seemed to immediately dislike the topic, or perhaps he disliked that I hadn't yet come up with something in particular yet and time was ticking...
I then told him about my idea for an anime recommendation website that allows users to generate compositions of anime image covers in order to share these as customised recommendations in JPG form to friends.
He heartily encouraged me to go ahead with it, and since he's the one giving me the grade at the end of the day I couldn't argue too much about it being trivial.
Looking at a few (7?) historic 1st-class projects at Portsmouth, it looks like they get the marks from having solid reports rather than being anything technically magical, so I'm feeling confident about it. I'll put extra work into critically evaluating my design choices, maybe look at bonus functionality, and should get a decent mark.
Maybe I'll post here again with a few questions/ideas with regards to this another time!
|
On November 12 2014 01:43 Nesserev wrote:Show nested quote +On November 11 2014 21:58 sabas123 wrote: he guys, Im currently following a community college level app development study and my school is inviting companies in my area so we can get an internship in our last semester.
any tips?
edit, something I did left out was that I have to hold a presentation about a social media website that I made with a group (well.. its more that I did 30% of the work, 1 guy the rest and the others 0 lines of code) are there anythings I should focus on or try to avoid in my presentation? Giving presentations is something that you learn by doing, and of course, you have to know what you're talking about. The only advice that I could give is: - make a proper presentation, and keep the viewer in mind - try not to use live demo's, but rather show everything through step-by-step images or clean videos, and offer hands-on experience afterwards with guidance (if necessary) Well, you probably will also have the opportunity to present your resume + portfolio. So: - make a nice resume in LaTeX, use a template; it'll definitely look better than 99.5% of all resumes out there - make a simple website to present your portfolio of work thank you!
I will follow your advice.
|
Something that helps improving your presentations is recording yourself and then criticizing yourself (and having others criticize you). It's brutal, but it really works. You'll notice your quirks, pacing, tone of your voice, things you didn't notice stand out, things you thought were glaring are fairly subdued.
Other basic tips: use a lot of different hand gestures, vary your tone, use an image on every slide.
|
Fuck xml (in context of reading/writing config files for various Java stuff). Seriously.
/rant
|
On November 12 2014 23:10 Manit0u wrote: Fuck xml (in context of reading/writing config files for various Java stuff). Seriously.
/rant
Wait what? You don't like having a metric shitton of overhead for even the simplest data serialization? Weirdo.
|
I need to distract myself from this. I can't take it any more...
Poll: Which one do you use?if (false == somwevar) (1) 6% if (somevar == false) (17) 94% 18 total votes Your vote: Which one do you use? (Vote): if (false == somwevar) (Vote): if (somevar == false)
Which and why?
Personally, I prefer to write/see the variable being evaluated before what it's being compared to. Makes more sense syntactically for me as it feels more natural.
|
On November 13 2014 00:30 Manit0u wrote:I need to distract myself from this. I can't take it any more... Poll: Which one do you use?if (false == somwevar) (1) 6% if (somevar == false) (17) 94% 18 total votes Your vote: Which one do you use? (Vote): if (false == somwevar) (Vote): if (somevar == false)
Which and why? Personally, I prefer to write/see the variable being evaluated before what it's being compared to. Makes more sense syntactically for me as it feels more natural. if (!somevar)
|
On November 13 2014 00:39 delHospital wrote:Show nested quote +On November 13 2014 00:30 Manit0u wrote:I need to distract myself from this. I can't take it any more... Poll: Which one do you use?if (false == somwevar) (1) 6% if (somevar == false) (17) 94% 18 total votes Your vote: Which one do you use? (Vote): if (false == somwevar) (Vote): if (somevar == false)
Which and why? Personally, I prefer to write/see the variable being evaluated before what it's being compared to. Makes more sense syntactically for me as it feels more natural. if (!somevar)
I prefer this as well.
|
On November 13 2014 00:39 delHospital wrote:Show nested quote +On November 13 2014 00:30 Manit0u wrote:I need to distract myself from this. I can't take it any more... Poll: Which one do you use?if (false == somwevar) (1) 6% if (somevar == false) (17) 94% 18 total votes Your vote: Which one do you use? (Vote): if (false == somwevar) (Vote): if (somevar == false)
Which and why? Personally, I prefer to write/see the variable being evaluated before what it's being compared to. Makes more sense syntactically for me as it feels more natural. if (!somevar)
I meant it in a more general way. Used false just as an example. This can as well be null, 'somestring' etc.
|
x == 0 For the same reasons.
Though I'm forced to do the opposite at work (for comparision against null). In C#. For C++, 0 == x is less error prone (won't compile if you write 0 = x), but in C# this only really matters in fringe cases.
|
(false == somevar) makes no logical sense in normal langauges?
|
On November 13 2014 03:25 sabas123 wrote: (false == somevar) makes no logical sense in normal langauges? Well, unless you are Yoda.
False the variable is.
|
Haha was confused for a second about the "if (someboolean == false)". But yeah, I use: if (blabla == "Hahaha") too. It never works too, I wonder why. Probably something to do with Java. (huehueuglylanguagehue).
Edit: Btw, trolling aside. There is a case to be made for if ("Hahaha".equals(someString)). Allows someString to be null and the comparison doesn't throw a NullPointerException. It may hide a bug though if you weren't expecting a null pointer ;D
|
yoyo anyone here use Delphi?
|
|
|
|
|
|