Esempio n. 1
0
int32_t main(int32_t argc, char **argv)
{
      
    struct mem_pool *test_mem_pool;
    struct mem_pool *test_mem_pool_2;
    struct mem_pool *test_mem_pool_3;
    gf_mem_init_mempool_list();
    gf_mem_acct_enable_set ();
    signals_setup();
    mem_acct_init(gf_common_mt_end+1);
    test_mem_t ** mem_array   = CALLOC(size,sizeof(test_mem_t * )); 
    test_mem_2_t ** mem_array2  = CALLOC(size,sizeof(test_mem_2_t * ));
    test_mem_3_t ** mem_array3  = CALLOC(size,sizeof(test_mem_3_t * ));
    int j;
    int i;
    CPU_TIME_START;
    test_mem_pool = mem_pool_new (test_mem_t, size);
    test_mem_pool_2 = mem_pool_new (test_mem_2_t, size);
    test_mem_pool_3 = mem_pool_new (test_mem_3_t, size);
    CPU_TIME_END_PRINT("mem pool");
    CPU_TIME_START;
    for(j=0; j<10000; j++){    
            if (!test_mem_pool)
            {
                DBG_PRINT("create mem pool error");
                return -1;
            }
        for(i=0; i<size; i++)
            mem_array[i] = (test_mem_t *)mem_get(test_mem_pool);
            mem_array2[i] = (test_mem_2_t *)mem_get(test_mem_pool_2);
            mem_array3[i] = (test_mem_3_t *)mem_get(test_mem_pool_3);
        for(i=0; i<size; i++)
            mem_put(mem_array[i]) ;
            mem_put(mem_array2[i]) ;
            mem_put(mem_array3[i]) ;
        
    }
    CPU_TIME_END_PRINT("mem pool");
    mem_pool_destroy(test_mem_pool);
    mem_pool_destroy(test_mem_pool_2);
    mem_pool_destroy(test_mem_pool_3);
    CPU_TIME_START;
    for(j=0; j<100; j++){
        for(i=0; i<size; i++)
            mem_array[i] = (test_mem_t *)MALLOC(sizeof(test_mem_t));
            mem_array2[i] = (test_mem_2_t *)MALLOC(sizeof(test_mem_2_t));
            mem_array3[i] = (test_mem_3_t *)MALLOC(sizeof(test_mem_3_t));
        for(i=0; i<size; i++)
            free (mem_array[i]);
            free (mem_array2[i]);
            free (mem_array3[i]);
    }
    CPU_TIME_END_PRINT("not mem pool");
    
    //getchar();
    return 0;
}
Esempio n. 2
0
static int
inst_am_zp(struct AddressingModeDesc *mode, struct machine *m)
{



  ADDR_SET_LOW(m->cpu.abr, mem_get(m,(m->cpu.reg.pc + 1)));
  ADDR_SET_HIGH(m->cpu.abr, mem_get(m,0x00));
  m->cpu.reg.pc += 2;
  return 1; 
}
Esempio n. 3
0
static int
inst_am_absy(struct AddressingModeDesc *mode, struct machine *m)
{
 
  ADDR_SET_LOW(m->cpu.abr, mem_get(m, m->cpu.reg.pc+ 1));
  
  ADDR_SET_HIGH(m->cpu.abr, mem_get(m, m->cpu.reg.pc+ 2));

 
  m->cpu.abr += m->cpu.reg.y;
  m->cpu.reg.pc += 3;
  return 1;

}
Esempio n. 4
0
seq_entry *seq_new( size_t max_seq_name, size_t max_seq )
{
    /* Martin A. Hansen, August 2008 */

    /* Initialize a new sequence entry. */

    seq_entry *entry = NULL;
    entry            = mem_get( sizeof( seq_entry ) );
    entry->seq_name  = mem_get( max_seq_name );
    entry->seq       = mem_get( max_seq );
    entry->seq_len   = 0;

    return entry;
}
Esempio n. 5
0
void* mem_find_free_in(memorytype_t type, uint32_t pageCount, bool_t align, bool_t reserve)
{
    //
    // find pageCount unoccupied pages in a row
    void* result = NULL;
    mem_memory_t* m = mem_get(type);
    uint32_t pagesFound = 0;
    uint32_t i;

    for (i = 0; i < m->pageTableTotalCount; i++)
    {
        if (!m->pageTableLookup[i].reserved && ((!align) || (pagesFound > 0) || ((i % pageCount) == 0)))
        {
            pagesFound++;
            if (pagesFound == pageCount)
            {
                result = mem_get_page_address(type, (i - pageCount) + 1);
                if (reserve)
                {
                    mem_reserve_pages(type, (i - pageCount) + 1, pageCount);
                }
                break;
            }
        }
        else
        {
            pagesFound = 0;
        }
    }
    return result;
}
Esempio n. 6
0
void * pc_alloc(struct pcache *pc)
{
	struct pool *pp;
	struct pc_pool *pcp, **item;

	abort_unless(pc);

	if ( l_isempty(&pc->avail) ) {
		if ( l_isempty(&pc->full) ) {
			if ( ! pc->mm || (pc->npools == pc->maxpools) )
				return NULL;

			pcp = mem_get(pc->mm, pc->pgsiz);
			if ( ! pcp ) 
				return NULL;
			pc_addpg(pc, pcp, pc->pgsiz);
		} else {
			pcp = (struct pc_pool *)pc->full.next;
			l_rem(&pcp->entry);
			l_ins(pc->avail.prev, &pcp->entry);
		}
	} 

	pcp = (struct pc_pool *)pc->avail.next;
	pp = &pcp->pool;

	if ( pp->fill == 1 ) {
		l_rem(&pcp->entry);
		l_ins(&pc->empty, &pcp->entry);
	}

	item = pl_alloc(pp);
	*item = pcp;
	return (char *)item + sizeof(cat_pcpad_t);
}
Esempio n. 7
0
openstack_subnet_p create_openstack_host_subnet(
		char* tenant_id,
		char* network_id,
		//char* subnet_name,
		char* subnet_id,
		UINT4 gateway_ip,
		UINT4 start_ip,
		UINT4 end_ip){
	openstack_subnet_p ret = NULL;
	ret = (openstack_subnet_p)mem_get(g_openstack_host_subnet_id);
	if (NULL != ret) {
		memset(ret,0,sizeof(openstack_subnet));

		strcpy(ret->tenant_id,tenant_id);
		strcpy(ret->network_id,network_id);
		//strcpy(ret->subnet_name,subnet_name);
		strcpy(ret->subnet_id, subnet_id);
		ret->gateway_ip = gateway_ip;
		ret->start_ip = start_ip;
		ret->end_ip = end_ip;
	}
	else {
		LOG_PROC("ERROR", "Openstack Subnet: Create failed, Can't get memory.");
	}

	return ret;
};
Esempio n. 8
0
openstack_security_p update_openstack_security_group(char* security_group)
{
	openstack_security_p security_p = g_openstack_security_list;

	while (security_p) {
		if (0 == strcmp(security_p->security_group, security_group)) {
			return security_p;
		}
		security_p = security_p->next;
	}

	// create
	security_p = (openstack_security_p)mem_get(g_openstack_security_group_id);
	if (NULL != security_p) {
		memset(security_p->security_group, 0, OPENSTACK_SECURITY_GROUP_LEN);
		memcpy(security_p->security_group, security_group, OPENSTACK_SECURITY_GROUP_LEN);
		security_p->next = g_openstack_security_list;
		g_openstack_security_list = security_p;
	}
	else {
		LOG_PROC("INFO", "Security: Get memeory fail!");
	}

	return security_p;
}
Esempio n. 9
0
// -----------------------------------------------------------------------
static int log_print_mem(char *b, int nb, uint16_t addr, int max_len, int terminator)
{
	int pos = 0;
	uint16_t ch;
	uint16_t word;
	int need = 1;
	int chars = 0;

	pos += sprintf(b+pos, "Data: \"");

	while (1) {
		if (chars >= max_len) break;
		if (need) {
			need = 0;
			if (!mem_get(nb, addr, &word)) break;
			addr++;
			ch = word >> 8;
		} else {
			need = 1;
			ch = word & 0xff;
		}
		if (ch == terminator) break;
		pos += sprintf(b+pos, "%c", ch);
		chars++;
	}
Esempio n. 10
0
char *bits2string( uint bin )
{
    /* Martin A. Hansen, June 2008 */
    
    /* Return a binary number as a string of 1's and 0's. */

    int   i;
    uint  j;
    char *string;
    
    string = mem_get( ( sizeof( uint ) * 8 ) + 1 );

    j = 1;
                                                                                                                                
    for ( i = 0; i < sizeof( uint ) * 8; i++ )                                                                          
    {                                                                                                                           
                                                                                                                                
        if ( ( bin & j ) != 0 ) {                                                                                               
            string[ 31 - i ] = '1';                                                                                             
        } else {                                                                                                                
            string[ 31 - i ] = '0';                                                                                             
        }                                                                                                                       
                                                                                                                                
        j <<= 1;                                                                                                                
    }                                                                                                                           
                                                                                                                                
    string[ i ] = '\0';                                                                                                         
                                                                                                                                
    return string;                                                                                                              
}
Esempio n. 11
0
void test_mem_resize_zero()
{
    fprintf( stderr, "   Testing mem_resize_zero ... " );

    size_t i;
    size_t size_before = 10;
    size_t size_after  = 100000;

    char *pt = NULL;

    pt = mem_get( size_before );

    memset( pt, '1', size_before );

    pt = mem_resize_zero( pt, size_before, size_after );

    assert( strlen( pt ) == size_before );

    for ( i = size_before; i <= size_after; i++ ) {
        assert( pt[ i ] == '\0' );
    }

    mem_free( ( void * ) &pt );

    fprintf( stderr, "OK\n" );
}
Esempio n. 12
0
openstack_node_p add_openstack_host_security_node(UINT1* data, openstack_node_p head_p)
{
	openstack_node_p node_p = head_p;

	if (NULL == data) {
		return head_p;
	}
	while (node_p) {
		if (data == node_p->data) {
			return head_p;
		}
		node_p = node_p->next;
	}

	openstack_node_p ret = NULL;
	ret = (openstack_node_p)mem_get(g_openstack_host_security_id);
	if (NULL == ret) {
		return head_p;
	}

	memset(ret, 0, sizeof(openstack_node));
	ret->data = data;
	ret->next = head_p;
	return ret;
};
Esempio n. 13
0
void test_mem_clone()
{
    fprintf( stderr, "   Testing mem_clone ... " );

    char   *pt;
    char   *pt_clone;
    size_t  pt_size = 10000;
    size_t  i;

    pt = mem_get( pt_size );

    memset( pt, 'X', pt_size );

    pt_clone = mem_clone( pt, pt_size );

    assert( pt_clone != pt );
    assert( &pt_clone != &pt );

    for ( i = 0; i < pt_size; i++ ) {
        assert( pt[ i ] == pt_clone[ i ] );
    }

    mem_free( ( void * ) &pt );
    mem_free( ( void * ) &pt_clone );

    fprintf( stderr, "OK\n" );
}
Esempio n. 14
0
/** Expand the buffer used by a memory stream.
 *
 * @param data mem stream
 * @param extra number of bytes to expand by
 * @return 0 on success, negative error otherwise
 */
static int mem_expand(MemData *data, size_t extra){
    int err = -ENOMEM;
    int delta = (extra < delta_min ? delta_min : extra);
    int buf_n;
    char *buf;
    if(data->buf_max > 0){
        int delta_max = data->buf_max - data->buf_n;
        if(delta > delta_max){
            delta = extra;
            if(delta > delta_max) goto exit;
        }
    }
    buf_n = data->buf_n + delta;
    buf = allocate(buf_n);
    if(!buf) goto exit;
    mem_get(data, buf, mem_len(data));
    data->hi = mem_len(data);
    data->lo = 0;
    deallocate(data->buf);
    data->buf = buf;
    data->buf_n = buf_n;
    err = 0;
  exit:
    if(err){
        data->err = -err;
    }
    return err;
}
Esempio n. 15
0
JNIEXPORT void JNICALL
Java_go_Seq_resetOffset(JNIEnv *env, jobject obj) {
	mem *m = mem_get(env, obj);
	if (m == NULL) {
		LOG_FATAL("resetOffset on NULL mem");
	}
	m->off = 0;
}
Esempio n. 16
0
JNIEXPORT void JNICALL
Java_go_Seq_ensure(JNIEnv *env, jobject obj, jint size) {
	mem *m = mem_get(env, obj);
	if (m == NULL || m->off+size > m->cap) {
		m = mem_ensure(m, size);
		(*env)->SetLongField(env, obj, memptr_id, (jlong)(uintptr_t)m);
	}
}
Esempio n. 17
0
JNIEXPORT void JNICALL
Java_go_Seq_recvRes(JNIEnv *env, jclass clazz, jint handle, jobject out_obj) {
	mem *out = mem_get(env, out_obj);
	if (out == NULL) {
		LOG_FATAL("recvRes out is NULL");
	}
	RecvRes((int32_t)handle, out->buf, out->len);
}
Esempio n. 18
0
JNIEXPORT void JNICALL
Java_go_Seq_free(JNIEnv *env, jobject obj) {
	mem *m = mem_get(env, obj);
	if (m != NULL) {
		unpin_arrays(env, m);
		free((void*)m->buf);
		free((void*)m);
	}
}
Esempio n. 19
0
void* mem_get_page_address(memorytype_t type, uint32_t pageNumber)
{
    mem_memory_t* m = mem_get(type);
    if (pageNumber >= m->pageTableTotalCount)
    {
        return NULL;
    }
    return (void*) (m->globalStartAddress + (pageNumber * MMU_MASTER_TABLE_PAGE_SIZE));
}
Esempio n. 20
0
void cb_init(struct circular_buffer *cb, _uint capacity, _uint sz) {
	cb->buffer = mem_get(capacity * (sz + 8)); /* 4 bytes for data_size, 4 bytes reserved (for push operations), 2 bytes for FCS */

	cb->buffer_end = cb->buffer + capacity * (sz + 8);
	cb->capacity = capacity;
	cb->count = 0;
	cb->sz = sz;
	cb->head = cb->buffer;
	cb->tail = cb->buffer;
}
Esempio n. 21
0
void test_mem_get()
{
    fprintf( stderr, "   Testing mem_get ... " );

    size_t  len = 1000000000;
    char   *pt  = mem_get( len );

    mem_free( ( void * ) &pt );

    fprintf( stderr, "OK\n" );
}
Esempio n. 22
0
void mem_reserve_page(memorytype_t type, uint32_t pageNumber)
{
    mem_memory_t* m = mem_get(type);
    if (pageNumber >= m->pageTableTotalCount)
    {
        return;
    }
    m->pageTableLookup[pageNumber].reserved = TRUE;
    m->pageTableAllocatedCount++;
    return;
}
Esempio n. 23
0
JNIEXPORT void JNICALL
Java_go_Seq_recv(JNIEnv *env, jclass clazz, jobject in_obj, jobject receive) {
	mem *in = mem_get(env, in_obj);
	if (in == NULL) {
		LOG_FATAL("recv in is NULL");
	}
	struct Recv_return ret = Recv(&in->buf, &in->len);
	(*env)->SetIntField(env, receive, receive_refnum_id, ret.r0);
	(*env)->SetIntField(env, receive, receive_code_id, ret.r1);
	(*env)->SetIntField(env, receive, receive_handle_id, ret.r2);
}
Esempio n. 24
0
/* Returns 0 on success, or a negative error code on failure.        */
int fd32_chdir(/*const */char *DirName)
{
  int               Res;
  char              Aux[FD32_LFNPMAX];
  char              Drive[FD32_LFNMAX];
  char             *Path;
  fd32_request_t   *request;
  void             *DeviceId;
  fd32_openfile_t   Of;
  fd32_close_t      C;
  tCds             *D;
  tCds            **CdsList = (tCds **) fd32_get_cdslist();

  LOG_PRINTF(("[CHDIR] In:\"%s\"\n", DirName));
  /* Open the directory to check if it is a valid directory */
  if ((Res = fd32_truename(Aux, DirName, FD32_TNSUBST)) < 0) return Res;
  for (;;)
  {
    Res = fd32_get_drive(Aux, &request, &DeviceId, &Path);
    if (Res < 0) return Res;
    Of.Size     = sizeof(fd32_openfile_t);
    Of.DeviceId = DeviceId;
    Of.FileName = Path;
    Of.Mode     = O_RDONLY | O_DIRECTORY;
    Res = request(FD32_OPENFILE, &Of);
    if (Res == FD32_OROPEN) break;
    if (Res != -ENOTMOUNT) return Res;
  }
  /* If we arrive here, the directory is valid */
  C.Size     = sizeof(fd32_close_t);
  C.DeviceId = Of.FileId;
  request(FD32_CLOSE, &C);
  if ((Res = fd32_truename(Aux, DirName, FD32_TNDOTS)) < 0) return Res;
  for (Res = 0; Aux[Res] != ':'; Drive[Res] = Aux[Res], Res++);
  Drive[Res] = 0;

  LOG_PRINTF(("[CHDIR] Setting the current dir of \"%s\" to \"%s\"\n", Drive, &Aux[Res + 1]));

  /* Search for the specified drive in the CDS list of the current process */
  for (D = *CdsList; D; D = D->Next)
    if (strcasecmp(D->Drive, Drive) == 0)
    {
      strcpy(D->CurDir, &Aux[Res + 1]);
      break;
    }

  /* If no CDS is present for the specified drive, add the entry */
  if ((D = (void *)mem_get(sizeof(tCds))) == NULL) return -ENOMEM;
  D->Next = *CdsList;
  strcpy(D->Drive, Drive);
  strcpy(D->CurDir, &Aux[Res + 1]);
  *CdsList = D;
  return 0;
}
Esempio n. 25
0
//UINT4 find_openstack_host_ports_by_subnet_id(char* subnet_id,openstack_port_p* host_list){
//	UINT4 ret = 0;
//	openstack_port_p port = NULL;
//	openstack_node_p node_p = NULL;
//	node_p = g_openstack_host_port_list;
//
//	while(node_p != NULL){
//		port = (openstack_port_p)(node_p->data);
//		if(strcmp(port->subnet_id,subnet_id) == 0){
//			host_list[ret] = port;
//			ret++;
//		}
//		node_p = node_p->next;
//	}
//	return ret;
//};
//
//void delete_openstack_host_port_by_tenant_id(char* tenant_id){
//	openstack_port_p port = NULL;
//	openstack_node node;
//	openstack_node_p node_p = &node,temp_p = NULL;
//	node_p->next = g_openstack_host_port_list;
//
//	while(node_p->next != NULL){
//		port = (openstack_port_p)(node_p->next->data);
//		if(strcmp(port->tenant_id,tenant_id) == 0){
//			temp_p = node_p->next;
//			node_p->next = temp_p->next;
//			destory_openstack_host_node(temp_p);
//			destory_openstack_host_port(port);
//		}else{
//			node_p = node_p->next;
//		}
//	}
//	g_openstack_host_port_list = node.next;
//	return;
//};
//void delete_openstack_host_port_by_network_id(char* network_id){
//	openstack_port_p port = NULL;
//	openstack_node node;
//	openstack_node_p node_p = &node,temp_p = NULL;
//	node_p->next = g_openstack_host_port_list;
//
//	while(node_p->next != NULL){
//		port = (openstack_port_p)(node_p->next->data);
//		if(strcmp(port->network_id,network_id) == 0){
//			temp_p = node_p->next;
//			node_p->next = temp_p->next;
//			destory_openstack_host_node(temp_p);
//			destory_openstack_host_port(port);
//		}else{
//			node_p = node_p->next;
//		}
//	}
//	g_openstack_host_port_list = node.next;
//	return;
//};
//void delete_openstack_host_port_by_subnet_id(char* subnet_id){
//	openstack_port_p port = NULL;
//	openstack_node node;
//	openstack_node_p node_p = &node,temp_p = NULL;
//	node_p->next = g_openstack_host_port_list;
//
//	while(node_p->next != NULL){
//		port = (openstack_port_p)(node_p->next->data);
//		if(strcmp(port->subnet_id,subnet_id) == 0){
//			temp_p = node_p->next;
//			node_p->next = temp_p->next;
//			destory_openstack_host_node(temp_p);
//			destory_openstack_host_port(port);
//		}else{
//			node_p = node_p->next;
//		}
//	}
//	g_openstack_host_port_list = node.next;
//	return;
//};
//void delete_openstack_host_port_by_port_id(char* port_id){
//	openstack_port_p port = NULL;
//	port = remove_openstack_host_port_by_port_id(port_id);
//	if(port != NULL){
//		destory_openstack_host_port(port);
//	}
//	return;
//};
////////////////////////////////////////////////////////////////////////
openstack_node_p create_openstack_host_node(UINT1* data){
	openstack_node_p ret = NULL;
	ret = (openstack_node_p)mem_get(g_openstack_host_node_id);
	if (NULL != ret) {
		memset(ret,0,sizeof(openstack_node));
		ret->data = data;
	}
	else {
		LOG_PROC("ERROR", "Create openstack host node: Create fail, can't get memory.");
	}
	return ret;
};
Esempio n. 26
0
JNIEXPORT void JNICALL
Java_go_Seq_send(JNIEnv *env, jclass clazz, jstring descriptor, jint code, jobject src_obj, jobject dst_obj) {
	mem *src = mem_get(env, src_obj);
	if (src == NULL) {
		LOG_FATAL("send src is NULL");
	}
	mem *dst = mem_get(env, dst_obj);
	if (dst == NULL) {
		LOG_FATAL("send dst is NULL");
	}

	GoString desc;
	desc.p = (char*)(*env)->GetStringUTFChars(env, descriptor, NULL);
	if (desc.p == NULL) {
		LOG_FATAL("send GetStringUTFChars failed");
	}
	desc.n = (*env)->GetStringUTFLength(env, descriptor);
	Send(desc, (GoInt)code, src->buf, src->len, &dst->buf, &dst->len);
	(*env)->ReleaseStringUTFChars(env, descriptor, desc.p);
	unpin_arrays(env, src);  // assume 'src' is no longer needed.
}
Esempio n. 27
0
void mem_free_page(memorytype_t type, uint32_t pageNumber)
{
    mem_memory_t* m = mem_get(type);
    if (pageNumber >= m->pageTableTotalCount)
    {
        return;
    }
    m->pageTableLookup[pageNumber].reserved = FALSE;
    m->pageTableAllocatedCount--;
    // reset the memory of the page
    memset(mem_get_page_address(type, pageNumber), 0, MMU_MASTER_TABLE_PAGE_SIZE);
}
Esempio n. 28
0
/** Read bytes from a memory stream into a buffer.
 *
 * @param io mem stream
 * @param buf buffer
 * @param n maximum number of bytes to read
 * @return number of bytes read on success, negative error code otherwise
 */
static int mem_read(IOStream *io, void *buf, size_t n){
    int k;
    MemData *data = get_mem_data(io);
    if(data->err) return -data->err;
    k = mem_len(data);
    if(n > k){
        n = k;
    }
    mem_get(data, buf, n);
    data->lo += n;
    return n;
}
Esempio n. 29
0
void* create_openstack_host_port(
		gn_switch_t* sw,
		UINT4 port,
		UINT4 ip,
		UINT1* mac,
		char* tenant_id,
		char* network_id,
		char* subnet_id,
		char* port_id,
		UINT2 security_num,
		UINT1* security_data){
	UINT8 dpid = 0;
	p_fabric_host_node node = NULL;
	openstack_port_p ret = NULL;
	ret = (openstack_port_p)mem_get(g_openstack_host_port_id);
	if (NULL != ret) {
		memset(ret,0,sizeof(openstack_port));

		if (NULL != tenant_id)
			strcpy(ret->tenant_id,tenant_id);
		if (NULL != network_id)
			strcpy(ret->network_id,network_id);
		if (NULL != port_id)
			strcpy(ret->port_id,port_id);
		if (NULL != subnet_id)
			strcpy(ret->subnet_id, subnet_id);
	//	ret->ip = ip;
	//	ret->sw = sw;
	//	if(sw != NULL)
	//		ret->dpid = sw->dpid;
	//	ret->port = port;
	//	memcpy(ret->mac, mac, 6);
		if (NULL != sw) {
			dpid = sw->dpid;
		}
		ret->security_num = security_num;
		if (NULL != security_data)
			ret->security_data = security_data;

		node = insert_fabric_host_into_list_paras(sw, dpid, port, mac, ip);
		if (NULL != node) {
			node->data = (void*)ret;
		}
		else {
			mem_free(ret, g_openstack_host_port_id);
		}
	}
	else {
		LOG_PROC("ERROR", "Create openstack host port: Can't get memory.");
	}
	return (void*)node;
};
/* The high-level memory allocation scheduler is implemented here */
static void GiveMemory() {

    int index;
    pcb* proc;
    pcb* stub;

    proc = new_proc;

    while (proc) {
        /*
         * Search for a new process that should be given memory.
         * Insert search code and criteria here.
         * Attempt to allocate as follows:
         */
        index = mem_get(proc->MEM_need);

        /* Allocation succeeded, now put in ready queue. */
        if (index >= 0) {

            /* Set the given memory */
            proc->MEM_base = index;

            /* Header of queue is one further */
            new_proc = proc->next;

            /* Enqueue the process in the ready queue, automatically removing
             * it from all the other queues by resetting prev and next pointers. */
            stub = ready_proc;
            if (stub) {
                /* If queue has elements, walk to the end. */
                while (stub->next)
                    stub = stub->next;
                stub->next = proc;
                proc->prev = stub;
                proc->next = NULL;
            }
            else {
                /* Only process in the new queue */
                ready_proc = proc;
                proc->next = NULL;
                proc->prev = NULL;

            }

            /* Set the next try. */
            proc = new_proc;
        } else {
            break;
        }
    }
}