Exemplo n.º 1
0
string_t PR_AllocTempStringLen			(progfuncs_t *progfuncs, char **str, unsigned int len)
{
	char **ntable;
	int newmax;
	int i;

	if (!str)
		return 0;

	if (prinst->numtempstrings == prinst->maxtempstrings)
	{
		newmax = prinst->maxtempstrings += 1024;
		prinst->maxtempstrings += 1024;
		ntable = memalloc(sizeof(char*) * newmax);
		memcpy(ntable, prinst->tempstrings, sizeof(char*) * prinst->numtempstrings);
		prinst->maxtempstrings = newmax;
		if (prinst->tempstrings)
			memfree(prinst->tempstrings);
		prinst->tempstrings = ntable;
	}

	i = prinst->numtempstrings;
	if (i == 0x10000000)
		return 0;

	prinst->numtempstrings++;

	prinst->tempstrings[i] = memalloc(len);
	*str = prinst->tempstrings[i];

	return (string_t)((unsigned int)i | 0x40000000);
}
Exemplo n.º 2
0
/*
 * don't do any of "storage compaction" nonsense, "just" the three modes:
 *   + cp == NULL ==> malloc
 *   + nbytes == 0 ==> free
 *   + else ==> realloc
 */
void *
memrealloc(void *cp, size_t nbytes)
{   
	union overhead *op;
  	size_t size;
	size_t alignpad;
	void *np;

	if (cp == NULL)
		return memalloc(nbytes, 8);

	if (nbytes == 0) {
		memfree(cp);
		return NULL;
	}

	op = ((union overhead *)cp)-1;
  	size = op->ov_index;
	alignpad = op->ov_alignpad;

	/* don't bother "compacting".  don't like it?  don't use realloc! */
	if (((1<<(size+MINSHIFT)) - (alignpad+sizeof(*op))) >= nbytes)
		return cp;

	/* we're gonna need a bigger bucket */
	np = memalloc(nbytes, 8);
	if (np == NULL)
		return NULL;

	memcpy(np, cp, (1<<(size+MINSHIFT)) - (alignpad+sizeof(*op)));
	memfree(cp);
	return np;
}
Exemplo n.º 3
0
static void *sextett_protection_write_raw(
    struct disk *d, unsigned int tracknr, struct stream *s)
{
    struct track_info *ti = &d->di->track[tracknr];
    uint32_t *block;

    /* Tracks 159 & 161: no data, all same data_bitoff (==0) */
    if (tracknr == 159) {
        /* Track 159 is only a protection track on Disk 1. */
        struct track_info *t158 = &d->di->track[158];
        return (t158->type == TRKTYP_sextett_protection) ? memalloc(0) : NULL;
    } else if (tracknr == 161) {
        /* Track 161: Protection on all disks. */
        ti->total_bits &= ~15;
        return memalloc(0);
    }

    /* Disk 1, Track 158: find the key */
    while (stream_next_bit(s) != -1) {
        if (s->word != 0x92459245)
            continue;
        ti->data_bitoff = s->index_offset_bc - 31;
        if (stream_next_bits(s, 32) == -1)
            break;
        block = memalloc(4);
        *block = htobe32(s->word);
        return block;
    }

    return NULL;
}
Exemplo n.º 4
0
/* void readFile()
 * Control the I/O.
 */
void readFile(File in, File out, int len, float qual,
    float avg, int minLen, int opt5, int opt3,
    int gz, int verbose) {
  char* head = (char*) memalloc(MAX_SIZE);
  char* seq = (char*) memalloc(MAX_SIZE);
  char* line = (char*) memalloc(MAX_SIZE);

  int count = 0, elim = 0;
  while (getLine(head, MAX_SIZE, in, gz) != NULL) {
    if (head[0] != '@')
      continue;

    // load sequence and quality scores
    if (getLine(seq, MAX_SIZE, in, gz) == NULL)
      exit(error("", ERRSEQ));
    for (int i = 0; i < 2; i++)
      if (getLine(line, MAX_SIZE, in, gz) == NULL)
        exit(error("", ERRSEQ));
    int end = strlen(line) - 1;
    if (line[end] == '\n')
      line[end] = '\0';
    if (end < len) {
      elim++;
      continue;
    }

    // trim read
    int st = 0;
    if (len)
      st = trimQual(line, len, qual, &end, opt5, opt3);
    if (avg && checkQual(line, st, end, avg)) {
      elim++;
      continue;
    }

    // print output
    if (st < end && end - st >= minLen) {
      gz ? gzprintf(out.gzf, "%s", head)
        : fprintf(out.f, "%s", head);
      for (int i = st; i < end; i++)
        gz ? gzputc(out.gzf, seq[i]) : putc(seq[i], out.f);
      gz ? gzprintf(out.gzf, "\n+\n")
        : fprintf(out.f, "\n+\n");
      for (int i = st; i < end; i++)
        gz ? gzputc(out.gzf, line[i]) : putc(line[i], out.f);
      gz ? gzprintf(out.gzf, "\n")
        : fprintf(out.f, "\n");
      count++;
    } else
      elim++;
  }

  if (verbose)
    printf("Reads printed: %d\nReads eliminated: %d\n",
      count, elim);

  free(seq);
  free(line);
  free(head);
}
Exemplo n.º 5
0
static struct file_info *open_file(char *name)
{
    struct file_info *fi = memalloc(sizeof(*fi));

    fi->line = 1;

    if (name[0] != '/') {
        char *path;
        if ((path = getcwd(NULL, 0)) == NULL)
            err(1, NULL);
        fi->name = memalloc(strlen(path) + strlen(name) + 2);
        sprintf(fi->name, "%s/%s", path, name);
        free(path);
        if ((fi->f = fopen(fi->name, "r")) == NULL) {
            memfree(fi->name);
            fi->name = memalloc(strlen(DEF_DIR) + strlen(name) + 2);
            sprintf(fi->name, "%s/%s", DEF_DIR, name);
            fi->f = fopen(fi->name, "r");
        }
    } else {
        fi->name = memalloc(strlen(name) + 1);
        strcpy(fi->name, name);
        fi->f = fopen(fi->name, "r");
    }

    if (fi->f == NULL) {
        memfree(fi->name);
        memfree(fi);
        fi = NULL;
    }

    return fi;
}
Exemplo n.º 6
0
/* int main()
 * Main.
 */
int main(int argc, char* argv[]) {
  line = (char*) memalloc(MAX_SIZE);
  hline = (char*) memalloc(MAX_SIZE);
  primo = NULL;
  getParams(argc, argv);
  freeMemory();
  return 0;
}
Exemplo n.º 7
0
// main
int main(int argc, char* argv[]) {
  root = (Node*) memalloc(sizeof(Node));
  root->child[0] = NULL;
  line = (char*) memalloc(MAX_SIZE);
  hline = (char*) memalloc(MAX_SIZE);
  getParams(argc, argv);
  freeMemory();
  return 0;
}
Exemplo n.º 8
0
int main(){ 
   printf("Test application\n");
   printf("sizeof int %d\n", sizeof(char *));
   printf("int shift %d\n", (1<<1));
   int array[5] = {2, 4, 8, 16, 0};
   int i;
   int *alloc;
   //meminit(4096,2,1,array);
   //int handler1=meminit(4096,2,1,array);
   
   int handler2=meminit(4096*2,2, 1, array);
   
   
	for(i=0; i<2048+16; i++) {
		printf("%d ", ((int*)alloc_array[handler2-100])[i]);
	}
	puts("");
    //memalloc(handler2, 16);
   alloc=memalloc(handler2, 8);
   memalloc(handler2, 16);
   
   //alloc=memalloc(handler2, 16);
   *alloc=124;
   for (i=0; i<511; i++){
      printf("i:%d\n", i);
      alloc=memalloc(handler2, 8);
      *alloc = 124;
   }
   int *test;
   test=memalloc(handler2,8);
   printf("test: %d\n", test);
   if(!test){
      printf("EXIT!\n");
      return 0;
   }
   
  // memalloc(handler2, 8);
   for(i=0; i<2048+16; i++) {
		printf("%d ", ((int*)alloc_array[handler2-100])[i]);
	}
	puts("");
    printf("alloc is %d\n", alloc);
    for (i=0; i<512; i++){
       memfree(alloc-((i)*2));
    }
    /*
    //memalloc(handler2, 8);
    memalloc(handler2, 16);
    memalloc(handler2, 8);
    */
    for(i=0; i<2048+16; i++) {
		printf("%d ", ((int*)alloc_array[handler2-100])[i]);
	}
	puts("");

   return 0;
}
Exemplo n.º 9
0
//////////////////////////////////////////////////////////////////////
// functions.
//////////////////////////////////////////////////////////////////////
int InitProjDB(const char* filename) {

	inter = (struct COUNTER*) memalloc(sizeof(struct COUNTER) * gN_ITEMS);
	intra = (struct COUNTER*) memalloc(sizeof(struct COUNTER) * gN_ITEMS);
	inter_freq_idx = (int*) memalloc(sizeof(int) * gN_ITEMS);
	intra_freq_idx = (int*) memalloc(sizeof(int) * gN_ITEMS);

	pDatasetMemMap = CreateMemMap(filename, 1536 * 1024 * 1024);
	return GetMemMapFileSize(pDatasetMemMap);
}
Exemplo n.º 10
0
static struct container *eadf_open(struct disk *d)
{
    struct disk_header dhdr;
    struct track_header thdr;
    struct disk_info *di;
    struct track_info *ti;
    unsigned int i;

    lseek(d->fd, 0, SEEK_SET);

    read_exact(d->fd, &dhdr, sizeof(dhdr));
    if (strncmp(dhdr.sig, "UAE-1ADF", sizeof(dhdr.sig)))
        return NULL;

    d->di = di = memalloc(sizeof(*di));
    di->nr_tracks = be16toh(dhdr.nr_tracks);
    di->track = memalloc(di->nr_tracks * sizeof(struct track_info));

    for (i = 0; i < di->nr_tracks; i++) {
        ti = &di->track[i];
        read_exact(d->fd, &thdr, sizeof(thdr));
        thdr.type = be16toh(thdr.type);
        if (thdr.type != 1) {
            warnx("Bad track type %u in Ext-ADF", thdr.type);
            goto cleanup_error;
        }
        init_track_info(ti, TRKTYP_raw);
        ti->len = be32toh(thdr.len);
        if (ti->len == 0) {
            init_track_info(ti, TRKTYP_unformatted);
            ti->total_bits = TRK_WEAK;
        } else {
            ti->dat = memalloc(ti->len);
            ti->total_bits = be32toh(thdr.bitlen);
        }
    }

    for (i = 0; i < di->nr_tracks; i++) {
        ti = &di->track[i];
        read_exact(d->fd, ti->dat, ti->len);
    }

    return &container_eadf;

cleanup_error:
    for (i = 0; i < di->nr_tracks; i++)
        memfree(di->track[i].dat);
    memfree(di->track);
    memfree(di);
    d->di = NULL;
    return NULL;
}
Exemplo n.º 11
0
static void adf_init(struct disk *d)
{
    struct disk_info *di;
    unsigned int i;

    d->di = di = memalloc(sizeof(*di));
    di->nr_tracks = 160;
    di->flags = 0;
    di->track = memalloc(di->nr_tracks * sizeof(struct track_info));

    for (i = 0; i < di->nr_tracks; i++)
        adf_init_track(&di->track[i]);
}
Exemplo n.º 12
0
void TTransBox::Show(int fast)
{
	Buf = (byte*) memalloc(w * h);
	Bkg = (byte*) memalloc(w * h);
	lockmem(Buf, w * h); lockmem(Bkg, w * h);
	GetBitmap32(x, y, Bkg, w, h);

	MouseHide();
	if (iniEnhancedGuiOn && (!fast))
		for (int i = w; i > 0; i -= w/OPEN_STEP) {Draw(i); SDL_Delay(15);}
	memcpy(Buf, Templ, w * h);
	Draw(0);
	MouseShow();
}
Exemplo n.º 13
0
/* int loadSeqs(FILE*)
 * Loads the primers from the given file.
 */
int loadSeqs(FILE* prim) {

  Primer* prev = NULL;
  int count = 0;
  while (fgets(line, MAX_SIZE, prim) != NULL) {

    if (line[0] == '#')
      continue;

    // load name and sequence
    char* name = strtok(line, CSV);
    char* seq = strtok(NULL, CSV);
    char* rev = strtok(NULL, DEL);
    if (name == NULL || seq == NULL || rev == NULL) {
      error("", ERRPRIM);
      continue;
    }

    // check for duplicate
    for (Primer* pc = primo; pc != NULL; pc = pc->next)
      if (!strcmp(pc->name, name))
        exit(error(name, ERRPREP));

    // create primer
    Primer* p = (Primer*) memalloc(sizeof(Primer));
    p->name = (char*) memalloc(1 + strlen(name));
    p->fwd = (char*) memalloc(1 + strlen(seq));
    p->rev = (char*) memalloc(1 + strlen(rev));
    strcpy(p->name, name);
    strcpy(p->fwd, seq);
    strcpy(p->rev, rev);

    // save sequence rc's
    p->frc = revComp(p->fwd);
    p->rrc = revComp(p->rev);

    p->fcount = p->rcount = p->fcountr = p->rcountr = 0;
    p->next = NULL;
    if (primo == NULL)
      primo = p;
    else
      prev->next = p;
    prev = p;
    p->len = 0;
    p->fpos = -1;
    count++;
  }

  return count;
}
Exemplo n.º 14
0
// char* copySeq()
char* copySeq(char* src, int pos, int size) {
  char* seq = (char*) memalloc(size);
  int i;
  for (i = 0; i < size; i++)
    seq[i] = src[pos + i];
  return seq;
}
Exemplo n.º 15
0
Arquivo: gray.c Projeto: abbrev/punix
STARTUP(void grayinit())
{
	size_t size = 3840*2;
	char *p0, *p1;
	p0 = memalloc(&size, 0); // allocate two contiguous buffers

	if (!p0) goto nomem;
	p1 = p0 + 3840;
	//memset(p0, 0, size);
	memmove(p0, LCD_MEM, 3840);
	//memmove(p1, LCD_MEM, 3840);
	memset(p1, 0, 3840);
	G.lcd.grayplanes[0] = p0;
	G.lcd.grayplanes[1] = p1;

	G.lcd.planes[0] = p0;
	G.lcd.planes[1] = p0;
	G.lcd.planes[2] = p1;
	G.lcd.third = -1;

#if 0
	/* gradient ramp */
	int i;
	for (i = 0; i < 3840; ++i) {
		p0[i] = (i/1920)&1 ? 0x00 : 0xff;
		p1[i] = (i/960)&1 ? 0x00 : 0xff;
	}
#endif

	G.lcd.grayinitialized = 1;
	return;

nomem:
	memfree(p0, 0);
}
Exemplo n.º 16
0
struct item *alloc()
{
	struct item *i = memalloc(sizeof *i);
	i->a = 13;

	return i;
}
Exemplo n.º 17
0
double powers_small_exp(int gb,long ex,big p)
{
    int iterations=0;
    big g,e,w;
    clock_t start;
    double elapsed;
    char *mem;

    mem=(char *)memalloc(3);
    g=mirvar_mem(mem,0);
    e=mirvar_mem(mem,1);
    w=mirvar_mem(mem,2);
    bigbits(gb,g);
    start=clock();
    lgconv(ex,e);
    do {
       power(g,ex,p,w);
       iterations++;
       elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
    } while (elapsed<MIN_TIME || iterations<MIN_ITERS);

    elapsed=1000.0*elapsed/iterations;
    if (ex==257L)
        printf("V - %8d iterations of %4d/e=F3 ",iterations,gb);
    if (ex==65537L)
        printf("V - %8d iterations of %4d/e=F4 ",iterations,gb);
    if (ex!=257L && ex!=65537L)
        printf("V - %8d iterations of %4d/e=%2ld ",iterations,gb,ex);
    printf(" %8.2lf ms per iteration\n",elapsed);
    memkill(mem,3);
   
    return elapsed;
}
Exemplo n.º 18
0
INLINE T *memconstructa(s32 n, const char *filename, int linenum, Args&&... args) {
  void *ptr = (void*) memalloc(n*sizeof(T)+DEFAULT_ALIGNMENT, filename, linenum);
  *(s32*)ptr = n;
  T *array = (T*)((char*)ptr+DEFAULT_ALIGNMENT);
  loopi(n) new (array+i) T(args...);
  return array;
}
Exemplo n.º 19
0
double powers_small_base(int g,int eb,big p)
{
    int iterations=0;
    big e,w;
    clock_t start;
    double elapsed;
    char *mem;

    mem=(char *)memalloc(2);

    e=mirvar_mem(mem,0);
    w=mirvar_mem(mem,1);
    bigbits(eb,e);
    start=clock();

    do {
        powltr(g,e,p,w);
        iterations++;
        elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
    } while (elapsed<MIN_TIME || iterations<MIN_ITERS);

    elapsed=1000.0*elapsed/iterations;
    printf("S - %8d iterations of  g=%d/%4d ",iterations,g,eb);
    printf(" %8.2lf ms per iteration\n",elapsed);

    memkill(mem,2);
    return elapsed;
}
Exemplo n.º 20
0
void mem_free(struct amiga_state *s, uint32_t addr, uint32_t bytes)
{
    struct memory *m = find_memory(s, addr, bytes);
    struct region *r, *prev, **pprev;

    ASSERT(m != NULL);

    regions_dump(m->free);

    pprev = &m->free;
    while (((r = *pprev) != NULL) && (r->end < addr))
        pprev = &r->next;

    if ((r != NULL) && (r->start == (addr + bytes))) {
        r->start -= bytes;
    } else {
        r = memalloc(sizeof(*r));
        r->start = addr;
        r->end = addr + bytes - 1;
        r->next = *pprev;
        *pprev = r;
    }

    prev = container_of(pprev, struct region, next);
    if ((pprev != &m->free) && (prev->end >= (addr-1))) {
        ASSERT(prev->end == (addr-1));
        prev->end = r->end;
        prev->next = r->next;
        memfree(r);
    }

    memset(&m->dat[addr - m->start], 0xaa, bytes);

    regions_dump(m->free);
}
Exemplo n.º 21
0
/**
 * @name new_search
 *
 * Create and initialize a new search record.
 */
SEARCH_RECORD *Wordrec::new_search(CHUNKS_RECORD *chunks_record,
                                   int num_joints,
                                   BLOB_CHOICE_LIST_VECTOR *best_char_choices,
                                   WERD_CHOICE *best_choice,
                                   WERD_CHOICE *raw_choice,
                                   STATE *state) {
  SEARCH_RECORD *this_search;

  this_search = (SEARCH_RECORD *) memalloc (sizeof (SEARCH_RECORD));

  this_search->open_states = MakeHeap (wordrec_num_seg_states * 20);
  this_search->closed_states = new_hash_table();

  if (state)
    this_search->this_state = new_state (state);
  else
    cprintf ("error: bad initial state in new_search\n");

  this_search->first_state = new_state (this_search->this_state);
  this_search->best_state = new_state (this_search->this_state);

  this_search->best_choice = best_choice;
  this_search->raw_choice = raw_choice;
  this_search->best_char_choices = best_char_choices;

  this_search->num_joints = num_joints;
  this_search->num_states = 0;
  this_search->before_best = 0;
  this_search->segcost_bias = 0;

  return (this_search);
}
Exemplo n.º 22
0
static void *bat_write_raw(
    struct disk *d, unsigned int tracknr, struct stream *s)
{
    struct track_info *ti = &d->di->track[tracknr];

    while (stream_next_bit(s) != -1) {

        uint32_t csum, dat[0x629*2];
        unsigned int i;
        char *block;

        if ((uint16_t)s->word != 0x8945)
            continue;

        ti->data_bitoff = s->index_offset_bc - 15;

        if (stream_next_bytes(s, dat, sizeof(dat)) == -1)
            break;
        mfm_decode_bytes(bc_mfm_even_odd, sizeof(dat)/2, dat, dat);

        csum = tracknr ^ 1;
        for (i = 0; i < 0x628; i++)
            csum += be32toh(dat[i]);
        if (csum != be32toh(dat[0x628]))
            continue;

        block = memalloc(ti->len);
        memcpy(block, dat, ti->len);
        set_all_sectors_valid(ti);
        ti->total_bits = 105500;
        return block;
    }

    return NULL;
}
Exemplo n.º 23
0
double powers_double(int gb,int eb,big p)
{
    int iterations=0;
    clock_t start;
    double elapsed;
    big g1,e1,g2,e2,w;
    char *mem;

    mem=(char *)memalloc(5);
    g1=mirvar_mem(mem,0);
    e1=mirvar_mem(mem,1);
    g2=mirvar_mem(mem,2);
    e2=mirvar_mem(mem,3);
    w=mirvar_mem(mem,4);
    bigbits(gb,g1);
    bigbits(gb,g2);
    bigbits(eb,e1);
    bigbits(eb,e2);
    start=clock();
    do {
        powmod2(g1,e1,g2,e2,p,w);
        iterations++;
        elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
    } while (elapsed<MIN_TIME || iterations<MIN_ITERS);

    elapsed=1000.0*elapsed/iterations;
    printf("D - %8d iterations of %4d/%4d ",iterations,gb,eb);
    printf(" %8.2lf ms per iteration\n",elapsed);

    memkill(mem,4);

    return elapsed;
}
Exemplo n.º 24
0
// readFile
int readFile(FILE* in) {
  int aorq = fastaOrQ(in);
  rewind(in);
  int count = 0;
  while (fgets(hline, MAX_SIZE, in) != NULL) {
    if (hline[0] == '#')
      continue;

    count++;
    if (fgets(line, MAX_SIZE, in) == NULL)
      exit(error("", ERRSEQ));
    int len = strlen(line) - 1;
    if (line[len] == '\n')
      line[len] = '\0';

    // add read to trie
    Node* n = checkNode(root, 0, len);
    if (n->child[0] == NULL && n->head == NULL) {
      n->head = (char*) memalloc(HEADER);
      int i;
      for (i = 1; hline[i] != '\0' && hline[i] != '\n' && i < HEADER; i++)
        n->head[i - 1] = hline[i];
      n->head[i - 1] = '\0';
    }

    // skip next 2 lines if fastq
    if (aorq)
      for (int i = 0; i < 2; i++)
        if (fgets(line, MAX_SIZE, in) == NULL)
          exit(error("", ERRSEQ));
  }
  printf("  reads: %d\n", count);
  return count;
}
Exemplo n.º 25
0
static void *skaermtrolden_hugo_write_raw(
    struct disk *d, unsigned int tracknr, struct stream *s)
{
    struct track_info *ti = &d->di->track[tracknr];
    struct disktag_disk_nr *disktag_disk_nr = (struct disktag_disk_nr *)
        disk_get_tag_by_id(d, DSKTAG_disk_nr);

    while (stream_next_bit(s) != -1) {

        uint32_t csum, sum, disk, trk, raw[5940/2];
        unsigned int i;
        char *block;
        int bad_original_sync;

        /* Accept our own rewritten second sync word (4489 -> 448a). */
        if ((s->word&~3) != ((tracknr & 1) ? 0x89448944 : 0x44894488))
            continue;
        bad_original_sync = (s->word == 0x44894489);

        ti->data_bitoff = s->index_offset - 31;

        if (stream_next_bytes(s, raw, 24) == -1)
            goto fail;
        mfm_decode_bytes(bc_mfm_even_odd, 4, &raw[0], &csum);
        csum = be32toh(csum);
        mfm_decode_bytes(bc_mfm_even_odd, 4, &raw[2], &disk);
        disk = be32toh(disk);
        mfm_decode_bytes(bc_mfm_even_odd, 4, &raw[4], &trk);
        trk = be32toh(trk);

        if (!disktag_disk_nr)
            disktag_disk_nr = (struct disktag_disk_nr *)
                disk_set_tag(d, DSKTAG_disk_nr, 4, &disk);
        if (disk != disktag_disk_nr->disk_nr)
            continue;

        if (trk != ((tracknr<<16) | tracknr))
            continue;

        if (stream_next_bytes(s, raw, sizeof(raw)) == -1)
            goto fail;
        for (i = sum = 0; i < 5940/4; i++) {
            mfm_decode_bytes(bc_mfm_even_odd, 4, &raw[2*i], &raw[i]);
            sum += be32toh(raw[i]);
        }

        /* See header comment for why we accept incorrect checksum MSB. */
        if ((sum != csum) &&
            !(bad_original_sync && (sum == (csum & 0x7fffffff))))
            continue;

        block = memalloc(ti->len);
        memcpy(block, raw, ti->len);
        set_all_sectors_valid(ti);
        return block;
    }

fail:
    return NULL;
}
Exemplo n.º 26
0
double mult2_precomp(int eb,big x,big y,big a2,big a6,int M,int A,int B,int C)
{
    big e,c,d;
    int iterations=0;
    ebrick2 binst;
    clock_t start;
    double elapsed;
    char *mem;

    mem=(char *)memalloc(3);
    e=mirvar_mem(mem,0);
    c=mirvar_mem(mem,1);
    d=mirvar_mem(mem,2);
    ebrick2_init(&binst,x,y,a2,a6,M,A,B,C,WINDOW,eb);
    bigbits(eb,e);
    start=clock();

    do {
       mul2_brick(&binst,e,c,d);
       iterations++;
       elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
    } while (elapsed<MIN_TIME || iterations<MIN_ITERS);

    elapsed=1000.0*elapsed/iterations;
    printf("EP - %8d iterations             ",iterations);
    printf(" %8.2lf ms per iteration\n",elapsed);

    ebrick2_end(&binst);
    memkill(mem,3);
   
    return elapsed;
}
int main(int argc, char **argv)
{
        int fd_v4l;
	quitflag = 0;

	pthread_t sigtid;
	sigemptyset(&sigset);
	sigaddset(&sigset, SIGINT);
	pthread_sigmask(SIG_BLOCK, &sigset, NULL);
	pthread_create(&sigtid, NULL, (void *)&signal_thread, NULL);

        if (process_cmdline(argc, argv) < 0) {
                return -1;
        }

        fd_v4l = v4l_capture_setup();
	if (g_mem_type == V4L2_MEMORY_USERPTR)
		if (memalloc(g_frame_size, TEST_BUFFER_NUM) < 0) {
			close(fd_v4l);
		}

	v4l_capture_test(fd_v4l);

	if (g_mem_type == V4L2_MEMORY_USERPTR)
		memfree(g_frame_size, TEST_BUFFER_NUM);

	return 0;
}
Exemplo n.º 28
0
/**********************************************************************
 * blobs_widths
 *
 * Compute the widths of a list of blobs. Return an array of the widths
 * and gaps.
 **********************************************************************/
WIDTH_RECORD *blobs_widths(TBLOB *blobs) {  /*blob to compute on */
  WIDTH_RECORD *width_record;
  TPOINT topleft;                /*bounding box */
  TPOINT botright;
  int i = 0;
  int blob_end;
  int num_blobs = count_blobs (blobs);

  /* Get memory */
  width_record = (WIDTH_RECORD *) memalloc (sizeof (int) * num_blobs * 2);
  width_record->num_chars = num_blobs;

  blob_bounding_box(blobs, &topleft, &botright); 
  width_record->widths[i++] = botright.x - topleft.x;
  /* First width */
  blob_end = botright.x;

  for (TBLOB* blob = blobs->next; blob != NULL; blob = blob->next) {
    blob_bounding_box(blob, &topleft, &botright); 
    width_record->widths[i++] = topleft.x - blob_end;
    width_record->widths[i++] = botright.x - topleft.x;
    blob_end = botright.x;
  }
  return (width_record);
}
Exemplo n.º 29
0
bool VideoStreamPlaybackWebm::open_file(const String &p_file) {

	file_name = p_file;
	webm = memnew(WebMDemuxer(new MkvReader(file_name), 0, audio_track));
	if (webm->isOpen()) {

		video = memnew(VPXDecoder(*webm, OS::get_singleton()->get_processor_count()));
		if (video->isOpen()) {

			audio = memnew(OpusVorbisDecoder(*webm));
			if (audio->isOpen()) {

				audio_frame = memnew(WebMFrame);
				pcm = (float *)memalloc(sizeof(float) * audio->getBufferSamples() * webm->getChannels());
			} else {

				memdelete(audio);
				audio = NULL;
			}

			frame_data.resize((webm->getWidth() * webm->getHeight()) << 2);
			texture->create(webm->getWidth(), webm->getHeight(), Image::FORMAT_RGBA8, Texture::FLAG_FILTER | Texture::FLAG_VIDEO_SURFACE);

			return true;
		}
		memdelete(video);
		video = NULL;
	}
	memdelete(webm);
	webm = NULL;
	return false;
}
Exemplo n.º 30
0
void BriefGo(char *MissionName)
{
    SetConstants();
    LinksSeq[0] = (char*)memalloc(8);
    
    strcpy(LinksSeq[0], MissionName);
    
    BriefInit(LinksSeq[0]);

  DrawOnScreen(1);
  FadeIn(Palette, 0);
  
  int BriefEvent; 
    // -7: Exit, -4: Up, -3: Down, -2: PgUp, -1: PgDown, 1..n: Odkazy HT
    do {
      BriefEvent = BriefGetEvent();
      BriefHandleEvent(BriefEvent);
  } while (BriefEvent != -7);
  
    BriefDone();
    FadeOut(Palette, 0);
    {
        TEvent e;
        do {GetEvent(&e);} while (e.What != evNothing);
    }
}